Report #35890
[bug\_fix] Container exits immediately or ignores runtime arguments \(CMD\) when using a custom ENTRYPOINT script
Ensure the ENTRYPOINT script ends with \`exec "$@"\` to execute the CMD arguments passed to the container.
Journey Context:
A developer writes an entrypoint script \(\`entrypoint.sh\`\) to perform runtime configuration, like dynamically generating config files based on environment variables. They set \`ENTRYPOINT \["/entrypoint.sh"\]\` and \`CMD \["gunicorn", "app:app"\]\`. The container starts, the script runs, but then the container exits with code 0, completely ignoring the CMD. They debug by running the container interactively and manually running the CMD, which works. The rabbit hole leads to understanding how Docker combines ENTRYPOINT and CMD: CMD is passed as command-line arguments to the ENTRYPOINT. Since the bash script doesn't read or execute these arguments, it simply exits after finishing its tasks, stopping the container. The fix is appending \`exec "$@"\` to the end of the entrypoint script, which executes the CMD arguments passed by Docker and replaces the shell process, ensuring the container stays alive and handles signals correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T14:43:10.204746+00:00— report_created — created