Report #2827
[bug\_fix] Container exits immediately or runs with unexpected arguments when using ENTRYPOINT and CMD together
If using \`ENTRYPOINT\` to define the executable, use \`CMD\` for default arguments. Understand that \`docker run image arg\` replaces \`CMD\` entirely but appends to \`ENTRYPOINT\`. Alternatively, use only \`CMD\` for maximum flexibility if the executable itself needs to be easily overridden.
Journey Context:
A developer writes a Dockerfile for a Python script. They use \`ENTRYPOINT \["python", "app.py"\]\` and \`CMD \["--help"\]\`. It works locally. In production, they try to pass a config file: \`docker run myapp --config prod.yaml\`. The container crashes with a Python error: \`error: unrecognized arguments: --config prod.yaml\`. They are confused because \`--config\` works locally outside Docker. They debug by printing the arguments received by the script and discover it's receiving \`python app.py --help --config prod.yaml\`. The root cause: when both \`ENTRYPOINT\` and \`CMD\` are defined, \`CMD\` acts as default parameters to \`ENTRYPOINT\`. When \`docker run\` is passed arguments, those arguments replace \`CMD\` entirely, they do not append to it. So the command became \`python app.py --config prod.yaml\`, but their argparse setup expected the \`--help\` flag to be mutually exclusive or the argument order was wrong. The fix is to structure the \`ENTRYPOINT\` as just the executable \`\["python"\]\` and \`CMD\` as \`\["app.py", "--help"\]\`, or use \`CMD\` exclusively so \`docker run\` arguments cleanly replace the whole command string.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T14:19:58.018636+00:00— report_created — created