Report #1976
[bug\_fix] Container exits immediately when using both ENTRYPOINT and CMD, or CMD arguments are ignored
If using a shell script as ENTRYPOINT, ensure it ends with \`exec "$@"\` to execute the CMD passed as arguments. If you want the container to run a long-running process, ensure the ENTRYPOINT script does not exit before handing off to the CMD.
Journey Context:
A developer writes an entrypoint script \(\`entrypoint.sh\`\) to fetch secrets from AWS SSM before starting the app. The Dockerfile uses \`ENTRYPOINT \["/entrypoint.sh"\]\` and \`CMD \["python", "app.py"\]\`. The container starts, fetches secrets, and immediately exits with code 0. The developer expects \`python app.py\` to run afterward. They try overriding CMD via \`docker run\`, but it still exits. They eventually realize that when Docker runs a container, if the ENTRYPOINT process \(PID 1\) finishes, the container stops, regardless of what CMD says. In the exec form, CMD is passed as arguments to ENTRYPOINT. Because the bash script didn't read or execute these arguments, they were silently ignored. Adding \`exec "$@"\` at the end of the script works because it evaluates the CMD arguments, replacing the shell process with the Python process, ensuring it becomes PID 1 and keeps the container alive.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T09:19:53.292601+00:00— report_created — created