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?
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:80binds only to localhost.-e KEY=value: set an environment variable.--env-file .envreads many at once.-v volume:/pathor-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 -fstops and removes in one go. Careful:docker container pruneremoves 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 -ffollows output liketail -f;--since 10mlimits to the last ten minutes.execruns a command inside an existing container. Useshwhen the image has nobash.inspect -ftakes a Go template to print just one field.statsshows 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.-fpicks another file.taggives an existing image an extra name, usually with a registry prefix before pushing.image pruneremoves dangling images (untagged leftovers). Careful: with-ait removes every image not used by a container.saveandloadmove 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
- Watchtower (maintained fork): automatic container image updates nicholas-fedor/watchtower Watchtower watches your running containers, pulls newer versions of their images and restarts them with the same settings. This fork continues the project after the original containrrr repository was archived. GitHub
- Uptime Kuma: self-hosted uptime monitoring louislam/uptime-kuma Uptime Kuma is a self-hosted monitoring tool with a web UI that checks websites, TCP ports, DNS, Docker containers and more, draws uptime history and sends alerts. One container is all it needs. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +4,408 chars