CertGrid CertGrid

Docker command cheat sheet

A searchable reference for the Docker commands you actually reach for. Every example marked with a play button was executed on Ubuntu 26.04 with Docker 29.7.2 - the output shown is what it printed. Commands without a play button are listed with their purpose only, because nothing here shows output that was not captured.

System and version

  • docker --version

    Print the client version only. Fast, and works even when the daemon is down.

    Full guide
  • docker version --format '{{.Server.Version}}'

    Ask the daemon its version. Fails if the daemon is unreachable, which makes it a liveness check.

    Full guide
  • systemctl is-active docker

    Confirm the daemon is running under systemd.

    Full guide
  • docker info

    Storage driver, cgroup version, root directory and resource totals for the whole engine.

    Full guide
  • docker system df

    Disk used by images, containers, volumes and build cache, with how much is reclaimable.

Images

  • docker pull IMAGE:TAG

    Download an image before you need it. Prints the digest that identifies it exactly.

    Full guide
  • docker images

    List local images with their IDs and on-disk sizes.

    Full guide
  • docker tag SRC TARGET

    Add a second name for an image. Copies nothing and succeeds silently.

    Full guide
  • docker history IMAGE

    Show each layer and what it cost. The fastest way to find why an image is large.

    Full guide
  • docker rmi IMAGE Destructive

    Remove a tag. Layers survive while any other tag still references them.

    Full guide

Containers

  • docker run -d --name NAME -p HOST:CTR IMAGE

    Start a detached container with a stable name and a published port.

    Full guide
  • docker ps

    List running containers. Add -a to include stopped ones.

    Full guide
  • docker stop | start | restart NAME

    Lifecycle control. Stop sends SIGTERM first; the container and its filesystem survive.

    Full guide
  • docker rm -f NAME Destructive

    Stop and remove in one step. The writable layer is destroyed with it.

    Full guide
  • docker rename OLD NEW

    Change a container's name without recreating it. Succeeds silently.

    Full guide
  • docker diff NAME

    Show what changed in the container's filesystem since it started. A for added, C changed, D deleted.

Logs and inspection

  • docker logs --tail N --timestamps NAME

    Read stdout and stderr. Add -f to follow live.

    Full guide
  • docker inspect --format '...' NAME

    Pull single fields out of the full JSON record. Works on containers, images, networks and volumes.

    Full guide
  • docker top NAME

    Processes inside the container, with host PIDs and the user each runs as.

    Full guide
  • docker stats --no-stream

    One sample of CPU, memory and network per container. Without --no-stream it streams forever.

    Full guide

Execution

  • docker exec NAME COMMAND

    Run a command inside a running container without restarting it.

    Full guide
  • docker exec -it NAME sh

    Interactive shell inside a running container. Use bash where the image has it.

    Full guide
  • docker cp NAME:/path ./local

    Copy files either direction. Works on stopped containers, which is how you retrieve a crash log.

    Full guide

Ports and networking

  • docker port NAME

    Show published port mappings without parsing inspect output.

    Full guide
  • docker network create NAME

    Create a user-defined bridge. Unlike the default bridge, it gives containers DNS by name.

    Full guide
  • docker network ls

    List networks and their drivers.

    Full guide
  • docker network inspect NAME

    Subnet, driver and every attached container with its address.

    Full guide

Volumes

  • docker volume create NAME

    Create storage Docker manages, addressed by name rather than host path.

    Full guide
  • docker run -v NAME:/path IMAGE

    Mount a named volume. Data survives the container being removed.

    Full guide
  • docker run -v /host:/ctr:ro IMAGE

    Bind-mount a host directory read-only. The kernel enforces it.

    Full guide
  • docker volume rm NAME Destructive

    Delete a volume and everything in it. No prompt, no undo.

    Full guide

Dockerfile builds

  • docker build -t NAME:TAG .

    Build an image from the Dockerfile in the current directory.

    Full guide
  • docker build --progress=plain .

    Full unfolded build log. Use when you need to see why a layer rebuilt.

    Full guide
  • docker build --no-cache .

    Ignore the cache and rebuild every layer. Slow by design - use to prove a build is reproducible.

    Full guide

Compose

  • docker compose up -d

    Create the network and start every service defined in compose.yaml.

  • docker compose ps

    Status of the services in this project only, rather than every container on the host.

  • docker compose logs --tail N

    Logs from every service, prefixed with the service name.

  • docker compose down Caution

    Stop and remove the project's containers and network. Named volumes are kept unless you add -v.

Registry

  • docker login REGISTRY

    Authenticate to a registry. Credentials are stored by the configured credential helper.

  • docker push NAME:TAG

    Upload an image. The repository name must match the registry and namespace you are pushing to.

  • docker image inspect IMG --format '{{index .RepoDigests 0}}'

    Get the immutable digest so you can pin a build rather than trusting a mutable tag.

    Full guide

Cleanup

  • docker system df

    Check what is actually using disk before removing anything.

  • docker rm -f NAME Destructive

    Remove a specific container. Prefer naming things over blanket removal.

  • docker system prune Whole-host

    Remove all stopped containers, unused networks, dangling images and build cache.

    Not demonstrated here. This was deliberately never executed while writing these guides - it removes resources across the whole host, including work unrelated to what you are doing. Read `docker system df` first, remove named resources second, and reach for prune only when you understand exactly what it will take.

Troubleshooting

  • curl -s -o /dev/null -w "%{http_code}" URL

    Prove a published port actually answers. Up in docker ps does not mean the service is ready.

    Full guide
  • docker inspect --format '{{.RestartCount}}' NAME

    A climbing restart count is a crash loop. docker ps hides it because the container keeps showing as Up.

    Full guide
  • getent group docker

    Check whether your user can reach the daemon socket without sudo.

    Full guide