JuniorDocker

What is the difference between CMD and ENTRYPOINT, and what is the exec versus shell form?

What they are really testing: Whether you know that ENTRYPOINT is the fixed executable and CMD the default/overridable args, plus that exec form matters for signal handling. People mix these up constantly.

A real interview question

What is the difference between CMD and ENTRYPOINT, and what is the exec versus shell form?

What most people say

drag me

They both set the command that runs in the container, so you can use either.

"Use either" is wrong: they behave differently with run-time args, and exec vs shell form affects whether the app gets shutdown signals. Treating them as interchangeable leads to ungraceful shutdowns and surprising overrides.

The follow-ups they ask next

  • Why does shell form (CMD app) cause problems with graceful shutdown?

    The shell becomes PID 1 and may not forward SIGTERM to your app, so the app never gets the signal and is SIGKILLed after the grace period. Exec form runs the app as PID 1 so it receives the signal.

  • How do ENTRYPOINT and CMD combine?

    ENTRYPOINT is the fixed command, CMD supplies default args appended to it. docker run args replace CMD but not ENTRYPOINT, so the program is fixed while its flags stay overridable.

What the interviewer is listening for

  • ENTRYPOINT=fixed exe, CMD=overridable args
  • Knows the combined pattern
  • Knows exec form for signal handling

What sinks the answer

  • "Use either, they are the same"
  • Unaware run args replace CMD not ENTRYPOINT
  • Does not know exec vs shell form

If you genuinely do not know

Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.

ENTRYPOINT is [the executable that always runs, not replaced by run args]; CMD is [default args, replaced by run args]. Pattern: [ENTRYPOINT = the binary, CMD = default flags]. Use [exec form (JSON array) so the app is PID 1 and gets SIGTERM], not [shell form, which can swallow the signal].

Keep going with docker

All 336 cloud engineer questions

Knowing the answer is not the same as recalling it under pressure

Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.

Start free