Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does "docker-compose down" invoke "docker stop" on each container?

Tags:

docker

I've written a Python program which ensures that its threads are gracefully stopped upon receiving a Unix SIGTERM signal. I understand that docker stop sends a SIGTERM request to the main process inside the container, and after a grace period, SIGKILL. The documentation for docker-compose down states that it "stops containers", but does not say explicitly how. I assume that it calls docker stop on each container?

like image 599
Kurt Peek Avatar asked Nov 07 '16 08:11

Kurt Peek


2 Answers

Following the links given by user2915097, it seems that this is indeed the case. The down method of the Project class invokes its stop method, which in terms seems to iterate over the containers and call stop on each one.

like image 193
Kurt Peek Avatar answered Oct 19 '22 23:10

Kurt Peek


NPM and Dockerfile ENTRYPOINT: Just Don't

I'm going to add this here so it is documented somewhere that some one else finds this answer too.

Node.JS Express + MongoDB app using Docker Compose. Pretty basic BUT it does not trigger the SIGINT or the SIGTERM events.

https://github.com/neozenith/hello-mongo/tree/4c1c3d9a55b574ba5a1c5f45dbf708c65a70c434

Solution

https://github.com/neozenith/hello-mongo/commit/c7e1b7497f204ffaa9387f99cb88188dadc1c094

BEFORE:

# WAS THIS
CMD [ "npm", "start" ]

AFTER:

# FUN FACT: DO NOT RUN ["npm", "start"] as the ENTRYPOINT
# It does not forward the SIGTERM and SIGINT events to Node
ENTRYPOINT [ "node", "server.js" ]

The exec form of ENTRYPOINT sends through the SIGTERM and SIGINT to PID 1.

https://docs.docker.com/engine/reference/builder/#exec-form-entrypoint-example

The key here is that npm does not forward that to node

like image 41
Josh Peak Avatar answered Oct 20 '22 00:10

Josh Peak