Report #38897
[gotcha] Why does my Docker container ignore SIGTERM and get force-killed after 10 seconds?
Use the exec form of ENTRYPOINT/CMD \(JSON array syntax\) in your Dockerfile, or explicitly 'exec' your binary in a shell script. This ensures your process runs as PID 1. Alternatively, use 'docker run --init' or add 'tini'/'dumb-init' as your ENTRYPOINT to handle signal forwarding and zombie reaping.
Journey Context:
In Linux, PID 1 \(the init process\) has special signal handling: it ignores signals with default actions \(like SIGTERM\) unless it explicitly registers a signal handler. When Docker starts a container, the process specified by ENTRYPOINT or CMD becomes PID 1. If you use the shell form of ENTRYPOINT \(e.g., 'ENTRYPOINT ./start.sh'\), Docker wraps your command in '/bin/sh -c', making the shell PID 1 and your actual application a child process \(PID 2\+\). Most shells \(like /bin/sh or bash\) do not forward received signals \(like SIGTERM from 'docker stop'\) to their child processes. Thus, when you run 'docker stop', the shell receives SIGTERM, ignores it \(because it's PID 1\), and Docker waits the grace period \(10s default\) before sending SIGKILL to the container, killing both shell and app ungracefully. The fix is to ensure your app runs as PID 1: use the exec form 'ENTRYPOINT \["./app"\]' \(JSON array\) which bypasses the shell, or use 'exec ./app' in your shell script to replace the shell process. For complex init requirements \(zombie reaping, signal forwarding\), use 'tini' \(available as 'docker run --init'\) or 'dumb-init' as PID 1, which then execs your app.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:45:56.250314+00:00— report_created — created