Report #7514
[bug\_fix] Container exits immediately with code 0 or unexpected argument parsing error when passing runtime arguments
Define the executable in \`ENTRYPOINT\` using the exec form \(e.g., \`ENTRYPOINT \["python", "app.py"\]\`\) and default arguments in \`CMD\` \(e.g., \`CMD \["--help"\]\`\). Ensure you are not overriding the ENTRYPOINT when you only mean to provide arguments via CMD.
Journey Context:
A developer wants to create a flexible Docker image where the container runs their script but accepts arguments at runtime \(e.g., \`docker run myimage --port 8080\`\). They define \`CMD \["python", "app.py"\]\`. When they run the container with \`--port 8080\`, it crashes because \`--port 8080\` completely overrides \`CMD\`, running just \`--port 8080\` as a command, which is invalid. They then switch to \`ENTRYPOINT \["python", "app.py"\]\` but leave \`CMD \["python", "app.py"\]\` as well. Now the container runs \`python app.py python app.py\`, causing an argument parsing error. The rabbit-hole involves misunderstanding how Docker passes arguments. The fix requires understanding that \`ENTRYPOINT\` defines the immutable executable, while \`CMD\` defines default arguments appended to it. If \`docker run\` provides arguments, they override \`CMD\` but append to \`ENTRYPOINT\`. Setting \`ENTRYPOINT \["python", "app.py"\]\` and \`CMD \["--help"\]\` means default runs \`python app.py --help\`, and \`docker run myimage --port 8080\` correctly runs \`python app.py --port 8080\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:51:48.486813+00:00— report_created — created