docker-compose up 和 docker-compose start 有什么区别?
What is the difference between docker-compose up and docker-compose start?
每当我执行
docker-compose start
docker-compose ps
我看到我的容器状态为 "UP"。如果我这样做
docker-compose up -d
我会看到更详细的内容,但它会具有相同的状态。这两个命令之间有什么区别吗?
docker-撰写开始
(https://docs.docker.com/compose/reference/start/)
Starts existing containers for a service.
docker-组合
(https://docs.docker.com/compose/reference/up/)
Builds, (re)creates, starts, and attaches to containers for a service.
Unless they are already running, this command also starts any linked services.
The docker-compose up
command aggregates the output of each container
(essentially running docker-compose logs -f
). When the command exits,
all containers are stopped. Running docker-compose up -d
starts the
containers in the background and leaves them running.
If there are existing containers for a service, and the service’s
configuration or image was changed after the container’s creation,
docker-compose up
picks up the changes by stopping and recreating the
containers (preserving mounted volumes). To prevent Compose from
picking up changes, use the --no-recreate
flag.
完整的 CLI 参考:
https://docs.docker.com/compose/reference/
在dockerFrequently asked questions里面解释的很清楚:
What’s the difference between up, run, and start?
Typically, you want docker-compose up
. Use up
to start or restart
all the services defined in a docker-compose.yml
. In the default
“attached” mode, you see all the logs from all the containers. In
“detached” mode (-d
), Compose exits after starting the containers, but
the containers continue to run in the background.
The docker-compose run
command is for running “one-off” or “adhoc”
tasks. It requires the service name you want to run and only starts
containers for services that the running service depends on. Use run
to run tests or perform an administrative task such as removing or
adding data to a data volume container. The run
command acts like
docker run -ti
in that it opens an interactive terminal to the
container and returns an exit status matching the exit status of the
process in the container.
The docker-compose start
command is useful only to restart containers
that were previously created, but were stopped. It never creates new
containers.
每当我执行
docker-compose start
docker-compose ps
我看到我的容器状态为 "UP"。如果我这样做
docker-compose up -d
我会看到更详细的内容,但它会具有相同的状态。这两个命令之间有什么区别吗?
docker-撰写开始
(https://docs.docker.com/compose/reference/start/)
Starts existing containers for a service.
docker-组合
(https://docs.docker.com/compose/reference/up/)
Builds, (re)creates, starts, and attaches to containers for a service.
Unless they are already running, this command also starts any linked services.
The
docker-compose up
command aggregates the output of each container (essentially runningdocker-compose logs -f
). When the command exits, all containers are stopped. Runningdocker-compose up -d
starts the containers in the background and leaves them running.If there are existing containers for a service, and the service’s configuration or image was changed after the container’s creation,
docker-compose up
picks up the changes by stopping and recreating the containers (preserving mounted volumes). To prevent Compose from picking up changes, use the--no-recreate
flag.
完整的 CLI 参考:
https://docs.docker.com/compose/reference/
在dockerFrequently asked questions里面解释的很清楚:
What’s the difference between up, run, and start?
Typically, you want
docker-compose up
. Useup
to start or restart all the services defined in adocker-compose.yml
. In the default “attached” mode, you see all the logs from all the containers. In “detached” mode (-d
), Compose exits after starting the containers, but the containers continue to run in the background.The
docker-compose run
command is for running “one-off” or “adhoc” tasks. It requires the service name you want to run and only starts containers for services that the running service depends on. Userun
to run tests or perform an administrative task such as removing or adding data to a data volume container. Therun
command acts likedocker run -ti
in that it opens an interactive terminal to the container and returns an exit status matching the exit status of the process in the container.The
docker-compose start
command is useful only to restart containers that were previously created, but were stopped. It never creates new containers.