本文介绍了我应该使用docker-compose up还是运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有理由使用 run 来启动 docker-compose.yml 文件,还是应该使用使用 up

Is there a reason to use run to start up a docker-compose.yml file or should you just use up?

我知道 run 可以启动特定的容器,但我指的是在不指定容器的情况下使用它的情况,这样它将启动所有yml容器。

I understand that run can start up a specific container, but I am referring to the case where you use it without specifying a container so that it starts up all of your yml containers.

推荐答案

在(2015)

As mentioned in docker-compose run (2015)

第二个区别是 docker-compose运行命令不创建服务配置中指定的任何端口

这样可以防止端口与已经打开的端口发生冲突。如果确实要创建服务的端口并将其映射到主机,请指定--service-ports标志:

The second difference is the docker-compose run command does not create any of the ports specified in the service configuration.
This prevents the port collisions with already open ports. If you do want the service's ports created and mapped to the host, specify the --service-ports flag:



$ docker-compose run --service-ports web python manage.py shell

因此,除非您有这些特定需求(覆盖命令或仅在不同端口上运行一个容器),否则 docker-compose up (即使对于一个容器)也足够。

So unless you have those specific needs (overriding a command or running only one container on different ports), docker-compose up (even for one container) is enough.

简单地是因为 docker-compose运行用于为服务运行一次性命令。

这意味着,如果您已经做了 docker-compose up ,您所有的容器都已经在 docker-compose.yml 的指定端口上运行。

进行 docker-compose run 在此阶段(执行一次性命令),如果它遵循相同的端口,则将立即失败。因此,默认情况下不创建这些端口。

Simply because docker-compose run is made to run one-off commands for your services.
That means that, if you already did a docker-compose up, all your containers are already running on their specified ports from docker-compose.yml.
Doing a docker-compose run at this stage (to execute a one-off command), if it was respecting the same port, would fail immediately. Hence the default non-creation of those ports.

另一个用例(在):






这些命令的最新版本(2019+)在:




  • docker compose run
  • docker compose up

这篇关于我应该使用docker-compose up还是运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:32