📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Docker CMD vs ENTRYPOINT

CMD vs ENTRYPOINT

5 min read Quiz at the end
Understand CMD vs ENTRYPOINT and always use exec form so containers handle signals correctly.

CMD vs ENTRYPOINT

# CMD — overridable default command
FROM ubuntu
CMD ["echo", "hello"]
# docker run myimage       -> echo hello
# docker run myimage ls    -> ls (CMD replaced)

# ENTRYPOINT — always executes, CMD = default args
FROM python:3.12
ENTRYPOINT ["python3", "app.py"]
CMD ["--port", "3000"]
# docker run myimage             -> python3 app.py --port 3000
# docker run myimage --port 8080 -> python3 app.py --port 8080

# Always use exec form (array) — handles signals correctly
CMD ["node", "server.js"]   # exec form - GOOD
CMD node server.js           # shell form - PID 1 = sh
Topic Quiz · 2 questions

Test your understanding before moving on

1. What happens when you run: docker run myimage ls (Dockerfile has CMD [echo hello])?
💡 CMD is completely replaced when you specify a command in docker run.
2. Which form of CMD correctly handles SIGTERM signals?
💡 Exec form makes the process PID 1 and receives OS signals; shell form wraps in /bin/sh.