Report #64681
[bug\_fix] Container exits immediately or arguments are incorrectly passed when overriding CMD at runtime
Use ENTRYPOINT for the base executable and CMD for default arguments, ensuring both are in exec form \(e.g., \`\["executable", "arg"\]\`\). Remember that arguments passed to \`docker run\` replace CMD entirely, they do not append to ENTRYPOINT unless CMD is also defined.
Journey Context:
A developer writes a Dockerfile with \`ENTRYPOINT \["python", "app.py"\]\` and \`CMD \["--help"\]\`. It works locally. Later, they run \`docker run myimage --port 8080\` and it crashes, complaining \`app.py\` doesn't recognize the arguments. They debug by printing \`sys.argv\` and see the arguments are mangled or missing. They go down a rabbit hole of shell form vs exec form syntax. The root cause is the interaction between ENTRYPOINT and CMD: if ENTRYPOINT is defined, CMD is always passed as arguments to the ENTRYPOINT. When \`docker run\` provides arguments, they replace the Dockerfile's CMD entirely. The fix works because it aligns with Docker's exact execution model: \`ENTRYPOINT\` defines the immutable binary, \`CMD\` defines the default flags, and runtime arguments cleanly replace the default flags without overriding the binary itself.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T15:03:05.229802+00:00— report_created — created