CMD and ENTRYPOINT

CMD and ENTRYPOINT tell a container what to run. ENTRYPOINT is the fixed program, CMD the default arguments, which docker run can replace.

How it works

Docker runs ENTRYPOINT followed by CMD. Anything typed after the image name in docker run replaces CMD; --entrypoint replaces ENTRYPOINT. An image that sets neither inherits those of its base image, which may not be what you want.

What breaks

Write them in exec form, a JSON array with double quotes. The shell form runs your program under /bin/sh -c, which swallows stop signals, and single quotes in the array silently turn it back into shell form.

In a Dockerfile

ENTRYPOINT ["node", "src/cli.js"]
CMD ["--help"]

See it break, then fix it

Write the Dockerfile or the compose file, type the docker commands, and watch a simulated server run them through reboots, upgrades and traffic. Free to start.