Knowledge Base
Authentication is disabled (development mode).

docker CMD vs. ENTRYPOINT

Edit

cmd docker dockerfile entrypoint run

The CMD instruction sets the command to be executed when running a container from an image.

  • CMD command param1 param2
  • CMD ["executable", "param1", "param2"]
  • CMD ["param1", "param2"] # -> ENTRYPOINT

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD, only the last one takes effect.

The purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.

If the user specifies arguments to docker run then they will override the default specified in CMD, but still use the default ENTRYPOINT.

Command line arguments to docker run <image> will be appended after all elements in an exec form ENTRYPOINT, and will override all elements specified using CMD.