Reputation: 179
I am currently using ENTRYPOINT ["/sbs/start.sh"] in a Dockerfile. So when a container starts, start.sh is run as pid 1 and my start.sh scripts spans two more child process to pid1. My question is how will docker treat the child process when I send a docker stop command to pid1? will the child process be gracefully stopped? or will they be killed forcefully?
In these cases where we have child processes, is it better to have a simple process supervisor and init system (https://github.com/Yelp/dumb-init or supervisor) to tackle these problems? if so, please suggest a lightweight init system? or can pid1 (start.sh in my case) take care of these problems?
output of ps -ef:
root 1 0 0 19:23 ? 00:00:00 /bin/bash /sbs/start.sh
root 13 1 0 19:23 ? 00:00:00 /sbs/bin/envconsul...
root 20 13 1 19:23 ? 00:00:21 /usr/lib/...
Any help is appreciated.
Upvotes: 3
Views: 4960
Reputation: 56538
Docker won't do anything here. It just signals PID 1. If PID 1 has children, it is expected to handle signaling them. This is the standard unix model.
For some more info you can read Docker and the PID 1 Zombie Reaping Problem.
When PID 1 exits, the container will exit, so the children will not necessarily exit gracefully. If you want them to exit gracefully you will have to have something hanging around that knows how to do that.
The link above offers one solution, an image from Phusion which has an init-style PID 1 to handle things like this. There are other solutions; that is only one option.
Upvotes: 7