About
cmd defines a command that should be run inside the container.
Definition
Inline
You can explicitly pass the cmd as argument to the docker cli.
docker run cmd # start a container and run a cmd
docker exec cmd # run a cmd against a running container
Example:
docker run -i -t ubuntu bash
- the image is ubuntu
- the entrypoint is the default /bin/sh -c because there is no ENTRYPOINT in the ubuntu dockerfile
- and the command is bash.
DockerFile
You can add a cmd 1) in a dockerfile
Management
Order of precedence
- The command line arguments to docker run will be appended after all elements in an exec form ENTRYPOINT
- Otherwise the CMD parameter of a dockerfile
List
docker inspect --format "{{range .Config.Cmd}}{{.}}{{end}}" containerOrImageName