moby: master process running in container doesn't get SIGTERM on stop with lxc
running:
Linux ubuntu 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
(ubuntu latest)
root@ubuntu:/home/sam# lxc-version
lxc version: 1.0.0.alpha1
run: docker run -i -t ubuntu /bin/bash
attempt to stop the container:
container fails to stop properly and reverts to kill
2013/10/29 16:24:47 error killing container 9d01aa5543a8df028df004c440240e72080b17eada1bf0cd9c5a092ae61139a4 (lxc-kill: failed to get the init pid
, exit status 255)
2013/10/29 16:24:57 Container 9d01aa5543a8df028df004c440240e72080b17eada1bf0cd9c5a092ae61139a4 failed to exit within 10 seconds of lxc SIGKILL - trying direct SIGKILL
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 33 (19 by maintainers)
Commits related to this issue
- fix: remove CMD from Dockerfile Refer to https://github.com/moby/moby/issues/2436#issuecomment-63662637 — committed to soundmemes/bot-crystal by vladfaust 7 years ago
- Merge pull request #2436 from arkodg/revert-syscall-reduction Revert "Adjust LockOSThread" — committed to cpuguy83/docker by selansen 5 years ago
I ran into the same issue with circusd, and I think it has to do with CMD exec form As stated on main docs, CMD can be called in three forms:
if CMD in your Dockerfile is called in shell form, your top process (PID 1) will be /bin/sh/ -c my_cmd And I have seen that my_cmd does not receive the docker stop signal
So I think that’s the solution, change from shell form to exec form. It works for me.
Example: circusd is startef from a script /bin/start.sh, which does some stuff and then execs circusd. https://registry.hub.docker.com/u/apsl/circusbase/dockerfile/
When using default CMD (shell mode):
If you do a ps axu inside container:
You can see /bin/start.sh is executed with /bin/sh -c, which has PID 1. Also you can see circusd has PID 8, altrough it was called with exec on start.sh. https://github.com/APSL/docker-circusbase/blob/master/start.sh
But when executed with exec mode:
Or changing CMD in your Dockerfile:
Then ps axu inside container shows cirusd process with PID 1. And now docker stops works well and receives QUIT/TERM signals.
Hope this helps.
Hi all,
I’d like to bring this issue up for attention, with a test case (/cc @jpetazzo). As this issue says, it seems like the process running inside the container isn’t getting the SIGTERM sent by Docker.
I have the following Python script:
The expected behavior is
SLEEPING
, followed by a 1000s pause (a long long time), followed by either one ofDONE
orGOT SIGNAL 15
if SIGTERM was received.Running the script outside of any container, we get the correct behavior:
I created an image, available on the public registry as
mpetazzoni/sigterm-test
, that includes this script and simply executes it when started:Starting the container, but killing the process manually as a host process, we get the correct behavior:
But using
docker stop
ordocker kill -TERM
both result in the incorrect behavior of the process being killed, but without having the chance to catch the SIGTERM signal:The Docker daemon log simply shows:
For reference: