Skip to content
Commitpedia
Log in Join & edit

Docker CLI cheat sheet

The Docker commands you reach for every day, grouped by what they act on: containers, images, volumes, networks, logs and cleanup, with the flags that matter.

Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?

Edit history of Docker CLI cheat sheet: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
3 min

Modern Docker groups commands by object: docker container ..., docker image ..., docker volume ..., docker network .... The old short forms such as docker ps and docker rmi still work and are what most people type. This sheet shows the short form where one exists. Add --help to any command for the full list of flags.

Run and manage containers

docker run -it --rm ubuntu:24.04 bash
docker run -d --name web -p 8080:80 nginx:1.27
docker run -d --name db -e POSTGRES_PASSWORD=example -v pgdata:/var/lib/postgresql/data postgres:17
docker run -d --restart unless-stopped --name app myimage:1.0

docker ps
docker ps -a
docker stop web
docker start web
docker restart web
docker rm web
docker rm -f web
docker container prune
  • -it: interactive terminal, for shells. --rm: delete the container when it exits.
  • -d: detached, run in the background. --name: a name to use instead of the ID.
  • -p HOST:CONTAINER: publish a port. -p 127.0.0.1:8080:80 binds only to localhost.
  • -e KEY=value: set an environment variable. --env-file .env reads many at once.
  • -v volume:/path or -v /host/path:/path: attach a named volume or a bind mount.
  • --restart unless-stopped: start again after a crash or reboot unless you stopped it yourself.
  • docker rm -f stops and removes in one go. Careful: docker container prune removes every stopped container.

Look inside a running container

docker logs web
docker logs -f --tail 100 web
docker exec -it web sh
docker exec web cat /etc/nginx/nginx.conf
docker inspect web
docker inspect -f '{{.NetworkSettings.IPAddress}}' web
docker stats
docker top web
docker cp web:/var/log/nginx/access.log ./access.log
docker port web
  • logs -f follows output like tail -f; --since 10m limits to the last ten minutes.
  • exec runs a command inside an existing container. Use sh when the image has no bash.
  • inspect -f takes a Go template to print just one field.
  • stats shows live CPU, memory and network usage for all containers.

Images

docker pull nginx:1.27
docker images
docker build -t myimage:1.0 .
docker build -t myimage:1.0 -f Dockerfile.prod .
docker tag myimage:1.0 registry.example.com/team/myimage:1.0
docker push registry.example.com/team/myimage:1.0
docker rmi myimage:1.0
docker image prune
docker image prune -a
docker history nginx:1.27
docker save -o nginx.tar nginx:1.27
docker load -i nginx.tar
  • build -t name:tag . builds from the Dockerfile in the current directory. -f picks another file.
  • tag gives an existing image an extra name, usually with a registry prefix before pushing.
  • image prune removes dangling images (untagged leftovers). Careful: with -a it removes every image not used by a container.
  • save and load move an image as a tar file between machines without a registry.

Volumes and networks

docker volume ls
docker volume create pgdata
docker volume inspect pgdata
docker volume rm pgdata
docker volume prune

docker network ls
docker network create appnet
docker run -d --name db --network appnet postgres:17
docker run -d --name app --network appnet myimage:1.0
docker network inspect appnet
docker network rm appnet

Containers on the same user-defined network reach each other by container name, so app can connect to db:5432. Careful: docker volume rm and docker volume prune delete data permanently.

Cleanup and disk usage

docker system df
docker system df -v
docker system prune
docker system prune -a --volumes

system prune removes stopped containers, unused networks, dangling images and build cache. Careful: -a also removes all unused images and --volumes removes all unused volumes, including data you may still want.

Compose shortcuts

docker compose up -d
docker compose ps
docker compose logs -f app
docker compose exec app sh
docker compose pull
docker compose up -d --build
docker compose down
docker compose down -v

Compose reads compose.yaml from the current directory. Careful: down -v also deletes the project’s named volumes.

Useful output formatting

docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
docker images --format '{{.Repository}}:{{.Tag}} {{.Size}}'
docker ps -q
docker stop $(docker ps -q)

-q prints only IDs, which makes it easy to feed one command’s result into another. The last line stops every running container.

Official documentation

Did this work for you?

No votes yet. Be the first.

If it did not work, the report form below tells the editors what went wrong.

See also

  • 0055 Docker basics: images, containers and the commands you need An image is a read-only package of an app and its dependencies, and a container is a running instance of it. Learn… Beginner · Explains an idea · Linux, macOS, Windows Article Docker basics 15 Oct 2026
  • 0056 Docker Compose: run a small web app with a database Docker Compose describes several containers, their ports, volumes and environment in one compose.yaml file, then starts them all with docker compose up. Intermediate · Step by step · Linux, macOS, Windows Article Docker basics · Docker Compose 15 Oct 2026
  • 0250 Containerize a Node.js app and run it with PostgreSQL using Docker Compose Package a small Node.js web app in a multi-stage Docker image, then run it next to PostgreSQL with Docker Compose, named volumes,… Intermediate · Guided project · Linux, macOS, Windows Article Docker basics · Docker Compose · PostgreSQL 15 Oct 2026
  • 0268 What is a container? A container is a lightweight box that packs a program with everything it needs so it runs the same on any computer. Beginner · Explains an idea · Any system Article Docker basics 15 Oct 2026
  • 0327 Docker images, containers and volumes explained An image is a read-only template, a container is a running copy of it with a thin writable layer, and a volume… Beginner · Explains an idea · Linux, macOS, Windows Article Docker basics 15 Oct 2026
  • 0328 Install Docker Engine on Ubuntu and Debian Set up Docker's official apt repository, install Docker Engine with the Compose and Buildx plugins, run hello-world and let your user run… Beginner · Step by step · Linux Article Docker basics · Packages & updates 15 Oct 2026

Repos in the wild

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Dominik +4,408 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?