beginnerDockerfile Instructions & Multi-Stage Builds

Why should you use exec form instead of shell form for ENTRYPOINT/CMD?

Shell form (CMD java -jar app.jar) runs the command via /bin/sh -c "...", making the shell PID 1 and your actual application a child process. Signals like SIGTERM sent by docker stop go to PID 1 (the shell), which often does not forward them to the child, so the app never gets a chance to shut down gracefully and Docker has to wait out the full grace period before SIGKILL. Exec form (CMD ["java","-jar","app.jar"]) runs the binary directly as PID 1, so it receives signals correctly.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What happens if both CMD and ENTRYPOINT are defined in a Dockerfile?← Back to all Docker questions