Docker · Containers in practice

What is the difference between ENTRYPOINT and CMD?

MediumentrypointcmdsignalsUpdated Oct 2026
Quiz this track

Short answer

ENTRYPOINT sets the fixed executable, while CMD supplies default arguments or a default command. Runtime arguments replace CMD but are appended to ENTRYPOINT.

If you define only CMD, docker run with a command replaces it entirely. If you define ENTRYPOINT, the container always runs that executable, and CMD becomes the default argument list that callers can override. Combining both is the usual pattern for a CLI-like image.

dockerfile
ENTRYPOINT ["node", "server.js"]
CMD ["--port", "3000"]
docker run api --port 8080 keeps the entrypoint and replaces the default arguments.

Shell form versus exec form

  • Exec form runs the binary directly, so it becomes PID 1 and receives signals
  • Shell form runs through /bin/sh -c, which may not forward SIGTERM
  • A shell-form CMD can cause slow shutdowns and lost graceful-drain logic
  • Use exec form unless you genuinely need shell expansion

Signal handling matters in production. If the process runs under a shell, docker stop sends SIGTERM to the shell, which may exit without passing it on. The container then waits for the timeout and is killed, so in-flight requests are dropped.

An entrypoint script should exec the final process, for example exec node server.js, so the real application keeps PID 1 and receives signals.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What happens to CMD when you pass a command to docker run?
  2. 2Why does exec form matter for graceful shutdown?
  3. 3How do you add an init process for signal handling?
  4. 4When would an entrypoint script be justified?

Say it in the interview

ENTRYPOINT defines the executable that always runs, and CMD provides default arguments or a default command. If I pass a command to docker run it replaces CMD, but with an entrypoint it becomes arguments to that entrypoint. I use the exec form so the application is PID 1 and receives SIGTERM, and any entrypoint script ends with exec so signals are not swallowed.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Docker mock interview and get scored feedback on depth, clarity and confidence.