Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose up, down, stop start difference

I cant find more information about those.

Should we use docker stop for containers which we started with docker start

Or same for docker-compose up?

What is the difference between stop and down?

like image 994
CursedChico Avatar asked Sep 26 '17 13:09

CursedChico


People also ask

What is difference between docker compose down and stop?

The docker-compose stop command will stop your containers, but it won't remove them. The docker-compose down command will stop your containers, but it also removes the stopped containers as well as any networks that were created. You can take down 1 step further and add the -v flag to remove all volumes too.

What is the difference between docker compose up and start?

docker-compose up : Builds, (re)creates, and starts containers. It also attaches to containers for a service. docker-compose start : Start the stopped containers, can't create new ones.

What does docker compose up and down do?

Stops containers and removes containers, networks, volumes, and images created by up . By default, the only things removed are: Containers for services defined in the Compose file.

What happens when docker compose up?

The docker compose up command aggregates the output of each container (like docker compose logs --follow does). When the command exits, all containers are stopped. Running docker compose up --detach starts the containers in the background and leaves them running.


4 Answers

In docker-compose help

stop               Stop services

down               Stop and remove containers and networks (optionally images and volumes as well)
like image 175
the genius Avatar answered Oct 12 '22 09:10

the genius


# Stop services only
docker-compose stop

# Stop and remove containers, networks..
docker-compose down 

# Down and remove volumes
docker-compose down --volumes 

# Down and remove images
docker-compose down --rmi <all|local> 
like image 28
Slipstream Avatar answered Oct 12 '22 11:10

Slipstream


Following are the differences among various docker-compose command options:

docker-compose up - start and restart all the services defined in docker-compose.yml

docker-compose down - command will stop running containers, but it also removes the stopped containers as well as any networks that were created. You can take down one step further and add the -v flag to remove all volumes too. This is great for doing a full blown reset on your environment by running docker-compose down -v.

docker-compose start - command will only restart containers stopped previously

docker-compose stop - command will stop running containers but won’t remove them

like image 13
Anshul Singhal Avatar answered Oct 12 '22 11:10

Anshul Singhal


Just to answer the other part of the question:

Use docker-compose up to start or restart all the services defined in a docker-compose.yml.

The docker-compose start command is useful only to restart containers that were previously created, but were stopped. It never creates new containers.

The docker-compose run command is for running “one-off” or “adhoc” tasks.

For further information visit this page.

like image 6
aBnormaLz Avatar answered Oct 12 '22 11:10

aBnormaLz