Skip to content

/compare/docker/cmd-vs-entrypoint

Dockerfile CMD vs ENTRYPOINT: differences and when to use each

The commands on this page have not been executed by our verification runner yet.updated 2026-10-20
tool
Docker
compares
CMD vs ENTRYPOINT

ENTRYPOINT defines the program the container runs; CMD provides default arguments, or the whole default command when there is no ENTRYPOINT. Arguments after the image name in docker run IMAGE args replace CMD but are appended to ENTRYPOINT. Use ENTRYPOINT for images that wrap one tool, and CMD alone for general images where users often run something else.

Criterion by criterion

CriterionCMDENTRYPOINT
Purposedefault command or default argumentsthe executable that always runs
docker run IMAGE x yreplaced by x yx y appended as arguments
Overrideany arguments after the image namedocker run --entrypoint PROGRAM
Several in one Dockerfileonly the last one countsonly the last one counts
Typical usenode, python and base imagesCLI tool images, wrapper scripts (docker-entrypoint.sh)

How they combine (exec form)

Dockerfiledocker run IMAGEdocker run IMAGE --help
CMD ["nginx", "-g", "daemon off;"]nginx -g "daemon off;"--help (fails: not a command)
ENTRYPOINT ["curl"]curlcurl --help
ENTRYPOINT ["curl"] + CMD ["https://example.com"]curl https://example.comcurl --help
dockerfile
FROM alpine:3.22
RUN apk add --no-cache curl
ENTRYPOINT ["curl", "-fsS"]
CMD ["--help"]

Exec form vs shell form

  • Exec form ["prog", "arg"] runs prog as PID 1, so it receives SIGTERM from docker stop. Prefer it.
  • Shell form prog arg runs /bin/sh -c "prog arg"; the shell is PID 1, variables are expanded, but signals often do not reach prog. A shell-form ENTRYPOINT also ignores CMD and docker run arguments.

Sources