Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between `docker-compose down` and Ctrl + C

Assume, you run a multi-container Docker application which consists of a database-container and an application-container. What is the difference between the following two methods to shut it down:

First method
1. Open a terminal and start the application with docker-compose up.
2. Shut the application down with Ctrl + C.

Second method
1. Open a terminal and start the application with docker-compose up.
2. Open a second terminal and shut the application down with docker-compose down.

In my understanding, both methods should do the exact same. However, when using the second method, I usually see some exceptions in the logs of the application that it can't connect to the database when it has already been shut down, which I otherwise don't see.

What is the recommended method?

like image 756
georg-un Avatar asked Mar 21 '19 14:03

georg-un


People also ask

What is docker compose down?

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.

What is the difference between docker and docker compose?

The key difference between docker run versus docker-compose is that docker run is entirely command line based, while docker-compose reads configuration data from a YAML file. The second major difference is that docker run can only start one container at a time, while docker-compose will configure and run multiple.

What is the difference between docker compose up and docker compose 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.

Does docker compose down Delete volumes?

The docker-compose down command helps to Stop and remove containers, networks, images, and volumes.


1 Answers

Running Ctrl+C will only stop the containers (it's actually equivalent to docker-compose stop) while docker-compose down will also remove the stopped containers and delete any networks created by the compose file.

Ctrl+C will only work however if all services are not started as detached (docker-compose up does not have the -d flag set)

As for the recommended method, it really depends on your particular use case. If you only need to stop the services, but not remove the containers, docker-compose stop will suffice. If you want to maybe rebuild the images or use different images, you might need to run docker-compose down.

like image 105
Bogsan Avatar answered Oct 23 '22 08:10

Bogsan