Report #95751
[bug\_fix] Docker CMD arguments are ignored or swallowed when using ENTRYPOINT with sh -c
Avoid using the shell form for ENTRYPOINT \(e.g., ENTRYPOINT \["sh", "-c", "my-app"\]\) if you need to pass CMD arguments. Instead, use the exec form directly \(ENTRYPOINT \["my-app"\]\) or ensure the shell command explicitly passes "$@" to the executable \(ENTRYPOINT \["sh", "-c", "my-app \\"$@\\"", "--"\]\).
Journey Context:
A developer writes a Dockerfile with 'ENTRYPOINT \["sh", "-c", "my-app"\]' and 'CMD \["--help"\]'. When the container runs, it ignores the --help flag. They try overriding it via 'docker run myimage --version', but it still runs without the flag. They go down a rabbit hole thinking CMD is broken or Docker Compose is overriding it incorrectly. They read the Docker documentation on how ENTRYPOINT and CMD interact. They discover that when using the shell form or explicitly invoking 'sh -c', the CMD string is passed as an argument to the shell, not to 'my-app'. Specifically, 'sh -c' only takes one argument string; any additional arguments \(like CMD\) are passed as positional parameters \($0, $1\) to the shell itself, not to the command string. To fix it, they must either use the exec form 'ENTRYPOINT \["my-app"\]' so CMD is naturally appended as arguments, or explicitly forward the shell parameters using 'ENTRYPOINT \["sh", "-c", "my-app \\"$@\\"", "--"\]'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:18:05.912342+00:00— report_created — created