What is the difference between CMD and ENTRYPOINT in a Dockerfile?
⚡
Quick Answer
ENTRYPOINT sets the executable that always runs and is not overridden by arguments to docker run (only by --entrypoint). CMD provides default arguments (or a default command) that are easily overridden at runtime.
Detailed Answer
The common pattern is ENTRYPOINT for the fixed binary and CMD for its default flags, so docker run image extra-args appends to the entrypoint. Use the exec form (JSON array) for both so signals (SIGTERM) reach your process for clean shutdown, rather than the shell form which wraps it in /bin/sh.
Code Example
ENTRYPOINT ["python", "app.py"] CMD ["--port", "8080"] # default arg, overridable at run time
💡
Interview Tip
Give the ENTRYPOINT-binary + CMD-default-args pattern and mention the exec form so SIGTERM reaches the app.
dockerdockerfilecmdentrypoint