Docker Cheat Sheet
A searchable Docker and Compose cheat sheet: running, building and inspecting containers, logs and exec, multi-arch builds, disk cleanup, registries and remote contexts.
Free · No sign-up · Your inputs stay in your browser
Reference
Docker and Compose cheat sheet
| Command | Does | Notes |
|---|---|---|
| docker ps -a | Containers, including stopped ones | --format 'table {{.Names}}\t{{.Status}}' to trim the columns. |
| docker compose up -d --build | Start the stack, rebuilding images | compose (v2 plugin) replaced docker-compose. |
| docker compose logs -f --tail=100 web | Follow one service's logs | |
| docker compose exec web sh | Shell into a running service | run --rm starts a new container instead. |
| docker compose down -v | Stop and remove containers and volumes | -v deletes the data volumes: read twice. |
| docker compose config | Print the resolved Compose file | Shows what environment interpolation produced. |
| docker logs -f --since 10m app | Follow a container's logs | |
| docker exec -it app bash | Shell in a running container | sh on Alpine and distroless-free images. |
| docker run --rm -it -v "$PWD":/app -w /app node:22 npm test | Run a one-off command in an image | --rm cleans up when it exits. |
| docker build -t app:1.4.2 . | Build and tag an image | --target build stops at a stage; --no-cache rebuilds everything. |
| docker buildx build --platform linux/amd64,linux/arm64 -t repo/app:1.4.2 --push . | Multi-architecture build | For Apple Silicon laptops and Graviton servers alike. |
| docker images / docker image ls | Local images | |
| docker image history app:1.4.2 | Layer sizes of an image | Find the step that made it big. |
| docker inspect app --format '{{.State.Health.Status}}' | Read one field of a container | |
| docker stats --no-stream | CPU, memory and I/O per container | |
| docker system df | Disk used by images, containers, volumes and cache | |
| docker system prune -a --volumes | Remove everything unused | Including volumes with data; prune without -a --volumes is gentler. |
| docker builder prune | Clear the build cache | Often the biggest item in system df. |
| docker cp app:/var/log/app.log . | Copy files out of (or into) a container | |
| docker network ls / inspect | Networks and who is attached | Containers on one user-defined network reach each other by name. |
| docker volume ls / inspect | Volumes and where they live on disk | |
| docker tag app:1.4.2 ghcr.io/acme/app:1.4.2 && docker push ghcr.io/acme/app:1.4.2 | Push to a registry | docker login ghcr.io first. |
| docker save app:1.4.2 | gzip > app.tgz | Export an image to a file | docker load < app.tgz on the other side. |
| docker restart app | Restart a container | restart: unless-stopped in Compose survives reboots. |
| docker update --memory 512m app | Change a running container's limits | |
| docker context use remote | Run Docker commands against another host | docker context create remote --docker host=ssh://user@host. |
For Docker Engine 25+ and the Compose v2 plugin (docker compose, with a space). Anything with prune or down -v deletes data; on a server, check docker system df and what is running first.
About this tool
Method, assumptions, practical next steps, and limits.
Compose v2
docker compose (with a space) is the Compose v2 plugin, which replaced the separate docker-compose binary in 2023. Commands and files are almost the same; the version key in Compose files is ignored. The Docker CLI reference documents every command.
Disk space
docker system df shows what images, containers, volumes and build cache use. Build cache is often the largest; docker builder prune clears it without touching volumes, which hold data.