Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gracefully shut down monogodb 0.8 running in docker

I am starting mongodb via the ENTRYPOINT config in a docker file. It works fine. However, when I execute:

docker stop <containerid>

it seems to be sending a SIGTERM to the process. Which means the mongod.lock file is not cleared. How can I gracefully shutdown a running docker container so that the right signals are sent to the process running inside docker ?

like image 912
canadadry Avatar asked Feb 18 '14 19:02

canadadry


2 Answers

I am not sure to understand. docker stop <id> will indeed send a SIGTERM. This is by design. If the process didn't shutdown properly within the timeout (default is 10 sec), then a SIGKILL is emitted.

At the moment, we do have some issue with the signal propagation though. It is due to the pid namespace and the fact that the process has a pid 1. This should get fixed soon with the new execution plugins.

like image 101
creack Avatar answered Nov 19 '22 23:11

creack


Using Docker 0.9 or later, it will send SigTerm to the 1st process (which is running inside container) by default.

But notice the environment variable file (/etc/default/docker in Ubuntu and /etc/sysconfig/docker in CentOS) should include DOCKER_OPTS=" -r=false " (or other_args=" -r=false" in CentOS) for stopping docker from autorestart container.

For example, I'm using this configuration: DOCKER_OPTS=" -g /mydir/docker -r=false --dns 8.8.4.4 "

If you want to run multi-process inside one container, you should using supervisord as the 1st process, supervisord will manage other processes and transfer signals to them.

like image 1
Tan Bui Avatar answered Nov 20 '22 00:11

Tan Bui