Report #3640
[bug\_fix] Container exits immediately with code 0 when using ENTRYPOINT and CMD together, or CMD arguments are ignored.
Add exec "$@" at the end of the ENTRYPOINT shell script to execute the CMD arguments passed to the container, ensuring the application process replaces the entrypoint script process to receive OS signals.
Journey Context:
A developer writes an entrypoint.sh script to dynamically generate a config file based on environment variables before starting the app. They set ENTRYPOINT \["/entrypoint.sh"\] and CMD \["node", "server.js"\]. The container builds, but on docker run, it exits immediately with code 0. They spend hours checking Node.js logs, thinking the app is crashing silently. They try running docker run -it ... sh but the entrypoint runs and exits. They add set -x to the script and see the script finishes successfully, but the node server.js command never runs. The root cause is that a shell script executed as an ENTRYPOINT does not automatically invoke the CMD. The script runs, does its setup, and exits, causing the container to stop. Adding exec "$@" at the end of the script passes control to the CMD arguments, and exec ensures Node runs as PID 1 to catch SIGTERM for graceful shutdowns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T17:50:26.755717+00:00— report_created — created