Loading...

About the Docker CLI Cheat Sheet

The Docker CLI is broad, and day-to-day work uses a small fraction of it. What separates comfortable use from constant searching is knowing which subcommand owns which noun — containers, images, volumes and networks each have their own management group, and the top-level shortcuts are aliases into them.

The commands worth internalising early are the diagnostic ones rather than the run ones. Inspecting a container's configuration, reading logs with a follow flag, executing a shell inside a running container, and listing what is actually consuming disk will resolve most problems you meet.

Disk usage is the recurring operational surprise. Stopped containers, dangling images, build cache and unused volumes accumulate quietly until a machine runs out of space, usually at an inconvenient moment. Knowing the difference between pruning images and pruning volumes matters, because one of those can delete data you wanted.

Frequently asked questions

Where did my disk space go?

Ask Docker directly with the system disk usage command, which breaks down images, containers, local volumes and build cache. Build cache is frequently the largest and least expected entry on a machine that builds often. Prune deliberately by category rather than reaching for a blanket cleanup, because volume pruning removes data.

What is the difference between stopping and removing a container?

Stopping halts the process but keeps the container's writable layer, so it can be started again with its filesystem changes intact. Removing deletes that layer permanently. A stopped container still consumes disk, which is why lists showing only running containers hide a common source of usage.

How do I get a shell in a container that has no shell?

Minimal and distroless images often have no shell at all, which is a security feature rather than an oversight. Attach a debug container that shares the target's namespaces, giving you tools without adding them to the image. On Kubernetes this is ephemeral debug containers; with Docker it means running a second container that joins the first's namespaces.

Why can my container not reach another container by name?

Name resolution only works on user-defined networks, not the default bridge. Create a network and attach both containers, or use Compose, which creates one automatically and makes service names resolvable. This is the most common cause of connection failures between containers that look correctly configured.

Do I lose data when a container is removed?

Anything written to the container's writable layer is lost. Data in a named volume or a bind mount survives, because it lives outside the container's lifecycle. If data must persist, put it in a volume deliberately rather than relying on the container continuing to exist.