Report #77906
[bug\_fix] Container exits immediately with code 0 when running 'docker run myimage', but works fine when running 'docker run myimage bash' or overriding the command.
Ensure the CMD instruction uses the exec form \(JSON array format like CMD \["executable", "param1"\]\) rather than the shell form \(CMD executable param1\). If the shell form is used with a simple command, the shell may exit, taking the container with it. Alternatively, ensure the primary process \(ENTRYPOINT/CMD\) runs in the foreground and does not daemonize.
Journey Context:
A developer writes a Dockerfile ending with 'CMD python app.py'. The container builds, but 'docker run' exits instantly. They attach to the container and find nothing in the logs. They run 'docker run -it myimage bash' and manually run 'python app.py', and it works perfectly. They suspect a background execution issue or a missing TTY. They add 'tty: true' to their docker-compose file, but it still crashes. The rabbit hole leads them to inspect the process tree inside the container. They realize that 'CMD python app.py' \(shell form\) executes as '/bin/sh -c python app.py'. If the Python script itself spawns a background process and exits, or if the shell interprets the command in a way that terminates, PID 1 dies, and the container halts. Switching to the exec form 'CMD \["python", "app.py"\]' bypasses the shell, making the Python process PID 1 directly, which correctly keeps the container alive as long as the script runs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:21:46.588844+00:00— report_created — created