Report #48844
[bug\_fix] Container takes 10\+ seconds to stop on docker stop; eventually exits with code 137 \(SIGKILL\)
Change the ENTRYPOINT or CMD from shell form \(ENTRYPOINT python app.py\) to exec form \(ENTRYPOINT \["python", "app.py"\]\), or use exec in a shell script entrypoint \(exec python app.py\). This makes the application process ID 1 \(PID 1\), allowing it to receive SIGTERM directly from the Docker daemon for graceful shutdown.
Journey Context:
A developer builds a Python web app and uses ENTRYPOINT python app.py. They notice that docker stop takes 10 seconds \(the default timeout\) and exits with 137. They add explicit signal handlers in Python for SIGTERM, but nothing changes. They exec into the container and run ps aux, discovering their app is running as PID 2, while /bin/sh is PID 1. In shell form, Docker invokes /bin/sh -c, which becomes PID 1. The shell does not forward signals like SIGTERM to child processes. When docker stop sends SIGTERM to PID 1, the shell ignores it. After 10 seconds, Docker sends SIGKILL. Switching to the exec form \(JSON array syntax\) replaces the shell entirely, making the app PID 1 and allowing it to catch the SIGTERM signal immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:28:07.755882+00:00— report_created — created