Docker Cheat Sheet

Comprehensive Docker Engine CLI reference for images, containers, networks, volumes, registries, contexts, and cleanup.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Basics

Core Docker client and daemon inspection commands.

Show Docker version

Display client and server version details.

bashANYversioninspect
bash
docker version
Notes

Useful to confirm API compatibility and engine version before troubleshooting.

Show Docker system info

Display engine-wide diagnostic and configuration information.

bashANYinfoinspectdiagnostics
bash
docker info
Notes

Shows storage driver, runtime, cgroup driver, registries, and resource counts.

Show Docker help

Show top-level help and subcommands.

bashANYhelpbasics
bash
docker --help
Notes

Use this to discover object-oriented commands such as `docker container`, `docker image`, and `docker network`.

List contexts

List available Docker contexts.

bashANYcontextbasics
bash
docker context ls
Notes

Contexts let you switch between local, remote, or cloud-managed endpoints.

Use a context

Switch the current Docker context.

bashANYcontextbasics
bash
docker context use default
Notes

Useful when working across local and remote engines.

Login to a registry

Authenticate to a registry such as Docker Hub or a private registry.

bashANYregistryauth
bash
docker login
Notes

Stores credentials via configured credential helper or config store.

Logout from a registry

Remove stored registry credentials.

bashANYregistryauth
bash
docker logout
Notes

Good hygiene on shared machines.

Images

Pull, tag, inspect, save, and manage images.

Pull an image

Download an image from a registry.

bashANYimagepull
bash
docker pull nginx:latest
Notes

Pin a specific tag or digest in production workflows.

Push an image

Upload an image to a registry.

bashANYimagepushregistry
bash
docker push ghcr.io/acme/web:1.0.0
Notes

Requires authentication and repository permissions.

List images

List local images.

bashANYimagelist
bash
docker images
Notes

Equivalent to `docker image ls`.

List images with image namespace

List local images using the image management namespace.

bashANYimagelist
bash
docker image ls
Notes

Object-oriented form that groups image subcommands together.

Show image history

Show the layer history of an image.

bashANYimagehistory
bash
docker image history nginx:latest
Notes

Helpful for understanding image growth and Dockerfile output.

Inspect an image

Show low-level JSON metadata for an image.

bashANYimageinspect
bash
docker image inspect nginx:latest
Notes

Great for checking entrypoint, environment, architecture, and labels.

Remove an image

Delete a local image.

bashANYimageremovecleanup
bash
docker image rm nginx:latest
Notes

Will fail if the image is referenced by existing containers unless forced.

Force remove an image

Force-remove a local image.

bashANYimageremovecleanup
bash
docker rmi -f nginx:latest
Notes

Useful when tags or stopped containers keep the image referenced.

Prune dangling images

Remove dangling images.

bashANYimageprunecleanup
bash
docker image prune
Notes

Reclaims space from untagged layers left after rebuilds.

Prune unused images

Remove all unused images.

bashANYimageprunecleanup
bash
docker image prune -a
Notes

More aggressive than pruning only dangling images.

Tag an image

Create or update an image tag.

bashANYimagetag
bash
docker tag myapp:dev ghcr.io/acme/myapp:1.0.0
Notes

Use tags to prepare images for different registries or release channels.

Save image to tar

Export one or more images to a tar archive.

bashANYimageexportarchive
bash
docker save -o myapp.tar myapp:1.0.0
Notes

Useful for air-gapped environments or offline transfer.

Load image from tar

Import images from a tar archive.

bashANYimageimportarchive
bash
docker load -i myapp.tar
Notes

Complements `docker save`.

Import rootfs as image

Import a tarball as an image.

bashANYimageimport
bash
docker image import rootfs.tar myimage:rootfs
Notes

Useful for creating simple images from exported root filesystems.

Build an image

Build an image from a Dockerfile.

bashANYimagebuild
bash
docker image build -t myapp:dev .
Notes

Equivalent to `docker build`.

Commit container changes to image

Create a new image from container changes.

bashANYimagecommitdebugging
bash
docker commit mycontainer myimage:debug
Notes

Handy for debugging, but prefer Dockerfiles for repeatable builds.

Push all tags

Push all local tags for a repository name.

bashANYimagepushregistry
bash
docker image push --all-tags ghcr.io/acme/myapp
Notes

Useful during migrations or synchronized releases.

Inspect a manifest

Inspect an image manifest or manifest list.

bashANYmanifestimageinspect
bash
docker manifest inspect alpine:latest
Notes

Helpful for multi-platform images and digests.

Containers

Create, run, inspect, and manage containers.

Run a container

Create and start a new container.

bashANYcontainerrun
bash
docker run nginx:latest
Notes

Shorthand for create + start with default options.

Run detached

Run a container in the background.

bashANYcontainerrundetached
bash
docker run -d --name web nginx:latest
Notes

Detached mode is common for services and daemons.

Run interactively

Run an interactive shell inside a new container.

bashANYcontainerinteractiverun
bash
docker run -it ubuntu:24.04 bash
Notes

Useful for exploration, debugging, and ephemeral workspaces.

Publish a port

Publish a container port to the host.

bashANYcontainernetworkports
bash
docker run -d -p 8080:80 nginx:latest
Notes

Maps host port 8080 to container port 80.

Set environment variables

Pass environment variables into the container.

bashANYcontainerenvrun
bash
docker run -e NODE_ENV=production myapp:latest
Notes

Can be repeated or loaded from a file with `--env-file`.

Load env file

Load environment variables from a file.

bashANYcontainerenvrun
bash
docker run --env-file .env myapp:latest
Notes

Handy for local development and repeatable container starts.

Mount a bind volume

Bind-mount a host directory into the container.

bashANYcontainervolumesrun
bash
docker run -v "$PWD":/app -w /app node:20 npm test
Notes

Good for local dev, compilers, and ad hoc tooling.

Use explicit mount syntax

Mount storage using long-form syntax.

bashANYcontainermountrun
bash
docker run --mount type=bind,src="$PWD",dst=/app myapp:latest
Notes

Long-form mount syntax is more explicit and extensible than `-v`.

Run and remove on exit

Automatically remove the container after it exits.

bashANYcontainercleanuprun
bash
docker run --rm alpine:latest echo hello
Notes

Ideal for short-lived commands and one-off jobs.

Create container without starting

Create a container but do not start it yet.

bashANYcontainercreate
bash
docker create --name web nginx:latest
Notes

Useful when you want to inspect or stage before execution.

Start a stopped container

Start one or more stopped containers.

bashANYcontainerstart
bash
docker start web
Notes

Use `-a` to attach immediately after start.

Stop a running container

Gracefully stop a running container.

bashANYcontainerstop
bash
docker stop web
Notes

Sends SIGTERM then SIGKILL after the timeout.

Kill a container

Force-stop a running container.

bashANYcontainerkill
bash
docker kill web
Notes

Sends SIGKILL by default or a custom signal with `-s`.

Restart a container

Restart one or more containers.

bashANYcontainerrestart
bash
docker restart web
Notes

Useful after config changes or transient failures.

Pause a container

Suspend all processes in a container.

bashANYcontainerpause
bash
docker pause web
Notes

Useful for testing or temporarily freezing workloads.

Unpause a container

Resume a paused container.

bashANYcontainerpause
bash
docker unpause web
Notes

Counterpart to `docker pause`.

List running containers

List running containers.

bashANYcontainerlist
bash
docker ps
Notes

Equivalent to `docker container ls`.

List all containers

List running and stopped containers.

bashANYcontainerlist
bash
docker ps -a
Notes

Useful for finding exited containers and previous runs.

List containers

List running containers with the container namespace.

bashANYcontainerlist
bash
docker container ls
Notes

Object-oriented alias for `docker ps`.

Execute command in running container

Run a command in a running container.

bashANYcontainerexecdebugging
bash
docker exec -it web sh
Notes

A standard way to inspect or debug a live container.

Attach to a running container

Attach local stdio to a running container.

bashANYcontainerattach
bash
docker attach web
Notes

Useful for foreground processes, but `docker exec` is often safer.

Show container logs

Print logs from a container.

bashANYcontainerlogsdebugging
bash
docker logs web
Notes

Pair with `-f` to follow logs in real time.

Follow container logs

Follow container logs from the last 100 lines.

bashANYcontainerlogsdebugging
bash
docker logs -f --tail=100 web
Notes

Great for watching startup and runtime behavior.

List processes in a container

Display running processes inside a container.

bashANYcontainerinspectprocesses
bash
docker top web
Notes

Useful for checking which process tree is active.

Stream resource usage

Stream live CPU, memory, network, and block I/O usage.

bashANYcontainerstatsmonitoring
bash
docker stats
Notes

Good for spotting runaway or memory-hungry containers.

Copy files into a container

Copy files from host to container.

bashANYcontainercopyfiles
bash
docker cp ./config.yml web:/etc/myapp/config.yml
Notes

Useful for debugging or quick experiments.

Copy files from a container

Copy files from container to host.

bashANYcontainercopyfiles
bash
docker cp web:/var/log/nginx/access.log ./access.log
Notes

Good for extracting logs and generated artifacts.

Rename a container

Rename an existing container.

bashANYcontainerrename
bash
docker rename web web-old
Notes

Helpful when rotating or staging replacements.

Remove a stopped container

Remove one or more stopped containers.

bashANYcontainerremovecleanup
bash
docker rm web
Notes

Use `-f` to remove a running container.

Force remove a running container

Force-remove a running container.

bashANYcontainerremovecleanup
bash
docker rm -f web
Notes

Equivalent to killing then removing it.

Prune stopped containers

Remove all stopped containers.

bashANYcontainerprunecleanup
bash
docker container prune
Notes

Helpful for reclaiming clutter and space.

Inspection and Debugging

Deep inspection, diffing, events, and daemon-side diagnostics.

Inspect a container

Show low-level JSON metadata for a container.

bashANYinspectcontainer
bash
docker inspect web
Notes

Inspect networking, mounts, environment, and restart policy.

Format inspect output

Render inspect output through a Go template.

bashANYinspectformatcontainer
bash
docker inspect -f '{{.NetworkSettings.IPAddress}}' web
Notes

Great for extracting just the data you need in scripts.

Show filesystem changes

Show filesystem changes in a container since it started.

bashANYinspectdebuggingfilesystem
bash
docker diff web
Notes

Useful for debugging and understanding mutable writes.

Stream Docker events

Stream real-time events from the daemon.

bashANYeventsmonitoring
bash
docker events
Notes

Helpful for automation, debugging, and understanding lifecycle actions.

Filter Docker events

Filter real-time events by type or action.

bashANYeventsmonitoring
bash
docker events --filter type=container --filter event=start
Notes

Useful when troubleshooting a specific resource kind.

List port mappings

List published ports for a container.

bashANYportsinspectcontainer
bash
docker port web
Notes

Quickly verify how container ports map to host ports.

Wait for container exit

Block until a container exits and print its exit code.

bashANYcontainerautomation
bash
docker wait web
Notes

Useful in scripts that need to synchronize with a container run.

Update container resources

Update resource limits on a running container.

bashANYcontainerresourcesruntime
bash
docker update --memory 512m --cpus 1.5 web
Notes

Common for tuning CPU and memory without recreating the container.

Stream recent events since timestamp

Show events from the past hour and continue streaming.

bashANYeventsmonitoring
bash
docker events --since 1h
Notes

Helpful during incident analysis.

Networks

Manage Docker networks and service connectivity.

List networks

List Docker networks.

bashANYnetworklist
bash
docker network ls
Notes

Shows built-in networks and user-defined bridges or overlays.

Create bridge network

Create a user-defined bridge network.

bashANYnetworkcreatebridge
bash
docker network create app-net
Notes

User-defined bridges provide automatic DNS between containers.

Create network with subnet

Create a network with a custom subnet.

bashANYnetworkcreateipam
bash
docker network create --subnet 172.20.0.0/16 app-net
Notes

Useful when you need predictable IP ranges.

Inspect network

Show low-level details of a Docker network.

bashANYnetworkinspect
bash
docker network inspect app-net
Notes

Inspect connected endpoints, subnets, and driver settings.

Connect container to network

Attach a running container to a network.

bashANYnetworkconnect
bash
docker network connect app-net web
Notes

Lets a container participate in multiple networks.

Disconnect container from network

Detach a container from a network.

bashANYnetworkdisconnect
bash
docker network disconnect app-net web
Notes

Useful when changing topology or isolating a workload.

Remove network

Delete one or more unused networks.

bashANYnetworkremovecleanup
bash
docker network rm app-net
Notes

Will fail if the network is still in use.

Prune unused networks

Remove all unused networks.

bashANYnetworkprunecleanup
bash
docker network prune
Notes

Helps keep the engine clean after many experiments.

Run on a specific network

Start a container attached to a chosen network.

bashANYnetworkrun
bash
docker run -d --name api --network app-net myapi:latest
Notes

Useful for service discovery between app containers.

Volumes and Mounts

Create and manage named volumes and mount strategies.

List volumes

List Docker volumes.

bashANYvolumelist
bash
docker volume ls
Notes

Named volumes are managed by the engine and survive container removal.

Create volume

Create a named volume.

bashANYvolumecreate
bash
docker volume create pgdata
Notes

Useful for databases and persistent application state.

Inspect volume

Show low-level details of a volume.

bashANYvolumeinspect
bash
docker volume inspect pgdata
Notes

Inspect mountpoint, driver, labels, and options.

Remove volume

Delete a named volume.

bashANYvolumeremovecleanup
bash
docker volume rm pgdata
Notes

Will fail if the volume is still attached unless forced by removing containers first.

Prune unused volumes

Remove all unused local volumes.

bashANYvolumeprunecleanup
bash
docker volume prune
Notes

Useful after many test runs that leave dangling data.

Mount named volume in container

Run a container with a named volume.

bashANYvolumerun
bash
docker run -d --name db -v pgdata:/var/lib/postgresql/data postgres:16
Notes

Common for persistent databases and stateful services.

Bind-mount host dir read-only

Mount a host directory as read-only.

bashANYmountbindreadonly
bash
docker run --mount type=bind,src="$PWD/config",dst=/app/config,readonly myapp:latest
Notes

Good for config files that should not be changed by the container.

Use tmpfs mount

Mount an in-memory tmpfs inside the container.

bashANYmounttmpfs
bash
docker run --tmpfs /tmp:rw,noexec,nosuid,size=64m myapp:latest
Notes

Useful for ephemeral sensitive temp data.

System and Cleanup

Space usage, pruning, and lifecycle cleanup.

Show disk usage

Display disk usage by images, containers, volumes, and build cache.

bashANYsystemcleanupdisk
bash
docker system df
Notes

Great for understanding where Docker is using space.

Prune unused data

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

bashANYsystemprunecleanup
bash
docker system prune
Notes

Good periodic cleanup for development machines.

Prune all unused data

Aggressively remove unused images and volumes too.

bashANYsystemprunecleanup
bash
docker system prune -a --volumes
Notes

Be careful: this can remove data you expected to keep.

Prune build cache

Remove unused build cache.

bashANYbuilderprunecleanup
bash
docker builder prune
Notes

Useful when BuildKit caches become large.

Prune all build cache

Remove all unused build cache, not only dangling records.

bashANYbuilderprunecleanup
bash
docker builder prune -a
Notes

Can reclaim significant disk space after many builds.

Registries and Manifests

Registry tagging, digest pinning, and manifest workflows.

Pull by digest

Pull an image by immutable digest.

bashANYregistrydigestimage
bash
docker pull nginx@sha256:<digest>
Notes

Prefer digests when you need strict reproducibility.

Run by digest

Run a container from an immutable image digest.

bashANYregistrydigestcontainer
bash
docker run nginx@sha256:<digest>
Notes

Prevents silent changes behind mutable tags such as `latest`.

Inspect repo digests

Display the digests associated with a local image.

bashANYregistrydigestinspect
bash
docker image inspect nginx:latest --format '{{json .RepoDigests}}'
Notes

Useful when promoting or pinning builds.

Create manifest list

Create a local manifest list from multiple platform images.

bashANYmanifestmultiarchregistry
bash
docker manifest create ghcr.io/acme/myapp:1.0.0 ghcr.io/acme/myapp:1.0.0-amd64 ghcr.io/acme/myapp:1.0.0-arm64
Notes

Part of a multi-architecture publishing workflow.

Annotate manifest entry

Annotate a manifest list entry with platform metadata.

bashANYmanifestmultiarchregistry
bash
docker manifest annotate ghcr.io/acme/myapp:1.0.0 ghcr.io/acme/myapp:1.0.0-arm64 --arch arm64
Notes

Useful when building a multi-platform image index manually.

Push manifest list

Push a manifest list to a registry.

bashANYmanifestmultiarchregistry
bash
docker manifest push ghcr.io/acme/myapp:1.0.0
Notes

Lets clients pull the right image for their platform automatically.

Contexts and Trust

Remote engine contexts and image trust basics.

Create a context

Create a named context that targets a specific Docker endpoint.

bashANYcontextremote
bash
docker context create prod --docker host=ssh://user@server
Notes

Very convenient for operating remote engines over SSH.

Inspect a context

Show the endpoint configuration for a context.

bashANYcontextinspect
bash
docker context inspect prod
Notes

Useful to confirm host, TLS, and metadata settings.

Remove a context

Delete a Docker context.

bashANYcontextcleanup
bash
docker context rm prod
Notes

Cleans up no-longer-used targets from your local client.

Inspect image trust data

Inspect content trust metadata for an image.

bashANYtrustsecurityregistry
bash
docker trust inspect alpine:latest
Notes

Relevant in environments using Docker Content Trust / Notary workflows.

Sign an image

Sign an image tag using Docker Content Trust.

bashANYtrustsecurityregistry
bash
docker trust sign acme/myapp:1.0.0
Notes

Useful in security-sensitive promotion pipelines.