Report #15979
[bug\_fix] Container exits immediately with code 0 or an error when running \`docker run myimage\`, despite the Dockerfile having both ENTRYPOINT and CMD set
Ensure the ENTRYPOINT script ends with \`exec "$@"\` so it passes execution to the CMD arguments, or use \`docker run --entrypoint\` to override the base image's entrypoint if it is swallowing the CMD.
Journey Context:
A developer builds an image based on a standard base image \(e.g., a custom entrypoint base image\). They add \`CMD \["node", "server.js"\]\` at the end of their Dockerfile. When they run the container, it exits immediately. They exec into the container but the server isn't running. They try overriding the command \`docker run myimage node server.js\`, still exits. The rabbit hole: the base image has an \`ENTRYPOINT \["/init.sh"\]\` that does some setup but \*doesn't\* execute the passed arguments. The developer's \`CMD\` is passed as arguments to \`/init.sh\`, which ignores them and exits. Adding \`exec "$@"\` to the end of \`/init.sh\` ensures the CMD arguments are executed as a command once the entrypoint finishes. The fix works because Docker passes CMD as parameters to ENTRYPOINT; without explicitly executing those parameters, the intended process never starts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:27:32.694322+00:00— report_created — created