Sachin
Sachin

Reputation: 23

Why systemd process running in docker container with PID 1 not forwarding SIGTERM to child processes on docker stop

We have Docker container which is running systemd as main process (PID 1). We have also started our worker processes in Docker container through systemd unit. Our Docker containers uses CentOS 7.2. We have configured the Docker stop timeout so that we can handle the graceful shutdown of worker processes running inside Docker container. When we are stopping Docker container, we can see SIGTERM is received to systemd process which is running with PID 1 inside container. Also container waits for stop timeout which we have configured. But systemd process is not forwarding this SIGTERM to our worker processes which we have started using systemd unit. From logs it looks like when systemd receives SIGTERM it tries to re-executes itself. We have tried with adding KillMode=mixed in our systemd unit file but it didn’t worked for us.

Is there any way to forward SIGTERM from systemd process to the child processes ?

Upvotes: 0

Views: 1788

Answers (2)

Guido U. Draheim
Guido U. Draheim

Reputation: 3271

Instead of running systemd itself you could also try with a replacement that provides a similar functionality. If you put the docker-systemctl-replacement as the entrypoint of the container then it will look for the systemd unit files you have provided - upon container start it runs ExecStart from unit descriptors and upon receiving SIGSTOP it will run ExecStop from each of the unit descriptors. It sounds like that's the functionality you want anyway.

Upvotes: 0

takaomag
takaomag

Reputation: 1635

Paste your docker run command, please.

I guess you have to add these 2 options.

--stop-signal=SIGRTMIN+3 --env container=docker

Upvotes: -2

Related Questions