188

Whenever I execute

docker-compose start 
docker-compose ps

I see my containers with the state "UP". If I do

docker-compose up -d

I will see more verbose but it will have the same state. Is there any difference between both commands?

Michael Villeneuve
  • 3,933
  • 4
  • 26
  • 40

3 Answers3

208

docker-compose start
(https://docs.docker.com/compose/reference/start/)

Starts existing containers for a service.

docker-compose up
(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.

For the complete CLI reference:
https://docs.docker.com/compose/reference/

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Luiz Lago
  • 2,599
  • 1
  • 12
  • 9
  • 4
    updated link to docker-compose CLI reference: https://docs.docker.com/compose/reference/ * docker-compose up: https://docs.docker.com/compose/reference/up/ * docker-compose start: https://docs.docker.com/compose/reference/start/ – michael May 16 '17 at 10:55
44

In docker Frequently asked questions this is explained very clearly:

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.

Nicolas Payart
  • 1,046
  • 14
  • 28
Supun Praneeth
  • 3,087
  • 2
  • 30
  • 33
7

What is the difference between up, run and start in Docker Compose?

  • docker-compose up: Builds, (re)creates, and starts containers. It also attaches to containers for a service.
  • docker-compose run: Run one-off or ad-hoc tasks based on the business requirements. Here, the service name has to be provided and the docker starts only that specific service and also the other services to which the target service is dependent (if any). It is helpful for testing the containers and also for performing tasks
  • docker-compose start: Start the stopped containers, can't create new ones.
Mostafa Wael
  • 2,750
  • 1
  • 21
  • 23