✦ For everyone, free.

Practical knowledge for real and everyday life

Home

4.2.6.1 CMD Default Command

A focused guide to CMD Default Command, connecting core concepts with practical Docker and container operations.

The CMD default command is whatever process CMD specifies as the one to run automatically when a container is started without an explicitly provided alternative — the practical effect of CMD being present in an image at all.

What Happens Without Any CMD

If a Dockerfile includes no CMD (and no ENTRYPOINT), the resulting image has no default command, and attempting to start a container without explicitly specifying one fails, since there is nothing for the container to actually execute.

FROM debian:bookworm-slim
COPY app /usr/local/bin/app
docker run myapp

Without a CMD or ENTRYPOINT, this command produces an error, since the image provides no default process to run.

Defining a Sensible Default

Specifying CMD gives every container started from the image a known, predictable default behavior, removing the need for every caller to specify the same command repeatedly.

CMD ["app"]
docker run myapp

This now succeeds, executing the default command defined by CMD.

The Default Can Reflect a Common Use Case

A thoughtfully chosen default command should reflect the image's most common intended use, while still allowing less common use cases to override it explicitly when needed.

CMD ["myapp", "serve"]
docker run myimage myapp migrate

The default supports the common case (serving the application) while still allowing an alternative subcommand to be specified when genuinely needed.

Verifying the Default Command

The default command configured for an image can be inspected directly without needing to actually start a container.

docker inspect myapp:1.0 --format '{{json .Config.Cmd}}'
Why a Well-Chosen Default Command Matters

A carefully chosen CMD default makes an image immediately usable with the simplest possible invocation, which is particularly valuable for images intended to be used by people unfamiliar with the specific application's full set of options, while still preserving flexibility for those who need it.