canadadry
canadadry

Reputation: 8453

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 ?

Upvotes: 16

Views: 14927

Answers (3)

Tan Bui
Tan Bui

Reputation: 81

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.

Upvotes: 1

Tan Bui
Tan Bui

Reputation: 81

I'm using docker 0.9. SIGTERM will be sent to process with PID=1 inside a container when call docker stop . So we can manage sub-processes with supervisord, runit.

The problem is when we call $ service docker stop|restart, or the host machine reset. Docker will not send SIGTERM to all running containers. I'm trying to solve this case.

Upvotes: 1

creack
creack

Reputation: 121712

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.

Upvotes: 12

Related Questions