CMD vs ENTRYPOINT
Select an icon to see what it is.
Step 6 of 6
A common pattern: a wrapper entrypoint
Many images set ENTRYPOINT to a small script that prepares things, such as writing config from environment variables, and then ends with exec "$@". That hands control to the CMD, which becomes PID 1. The official nginx image works this way, so docker run nginx and docker run nginx nginx -v both go through its entrypoint script.
PrevNext
Wrapper entrypoint (shape)
ENTRYPOINT ["/docker-entrypoint.sh"]CMD ["nginx", "-g", "daemon off;"]the script finishes with: exec "$@" (runs the CMD as PID 1)
Try it yourself
Build a tiny image and change how it starts.
$ printf 'FROM alpine\nENTRYPOINT ["echo"]\nCMD ["hello"]\n' > Dockerfile$ docker build -t cmddemo .$ docker run --rm cmddemo$ docker run --rm cmddemo world$ docker run --rm --entrypoint cat cmddemo /etc/os-release$ docker image inspect cmddemo --format 'entrypoint={{.Config.Entrypoint}} cmd={{.Config.Cmd}}'