Report #26991
[bug\_fix] Docker run arguments override CMD or break ENTRYPOINT unexpectedly
Use the exec form for ENTRYPOINT \(\`ENTRYPOINT \["/entrypoint.sh"\]\`\) and combine it with CMD \(\`CMD \["start"\]\`\). Ensure the entrypoint script ends with \`exec "$@"\` to pass execution to the CMD or runtime arguments.
Journey Context:
A developer writes an entrypoint script that waits for a database and then starts the app. They define it as \`ENTRYPOINT /entrypoint.sh\` \(shell form\) and \`CMD \["start-app"\]\`. When running \`docker run myimage\`, it works. But when running \`docker run myimage debug-mode\`, the container ignores 'debug-mode' and just runs 'start-app', or crashes. The developer dives into shell scripting debugging, thinking their argument parsing is wrong. The root cause is using the shell form of ENTRYPOINT. The shell form invokes a shell \(\`/bin/sh -c\`\) and completely ignores the CMD instruction or any arguments passed via \`docker run\`. Switching to the exec form \`ENTRYPOINT \["/entrypoint.sh"\]\` ensures the script is executed directly as PID 1, and adding \`exec "$@"\` at the end of the script properly hands off execution to the CMD or runtime arguments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:42:14.464737+00:00— report_created — created