Report #104664
[bug\_fix] ENTRYPOINT vs CMD: container exits immediately after start
Use the exec form of ENTRYPOINT and CMD to avoid shell pid 1 issues. For example: \`ENTRYPOINT \["executable", "param"\]\` and \`CMD \["param2"\]\`. If using shell form, ensure the main process handles signals correctly. For scripts, use \`exec\` to replace the shell.
Journey Context:
I wrote a Dockerfile with \`ENTRYPOINT ./start.sh\` and \`CMD \["--flag"\]\`. The container started but exited immediately. I checked logs and saw the script ran but then exited. The problem was that \`ENTRYPOINT\` in shell form invokes \`/bin/sh -c "./start.sh"\` which spawns a shell as PID 1, and the script didn't exec the final process, so the shell exited. The fix was to change to exec form: \`ENTRYPOINT \["./start.sh"\]\` and ensure the script uses \`exec\` for the final binary. This is a classic Docker pitfall explained in many guides. I also learned that BuildKit doesn't change this behavior.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-20T20:06:12.617087+00:00— report_created — created