Skip to content
gohacks.dev
DevOps

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

CommandDoesNotes
docker ps -aContainers, including stopped ones--format 'table {{.Names}}\t{{.Status}}' to trim the columns.
docker compose up -d --buildStart the stack, rebuilding imagescompose (v2 plugin) replaced docker-compose.
docker compose logs -f --tail=100 webFollow one service's logs
docker compose exec web shShell into a running servicerun --rm starts a new container instead.
docker compose down -vStop and remove containers and volumes-v deletes the data volumes: read twice.
docker compose configPrint the resolved Compose fileShows what environment interpolation produced.
docker logs -f --since 10m appFollow a container's logs
docker exec -it app bashShell in a running containersh on Alpine and distroless-free images.
docker run --rm -it -v "$PWD":/app -w /app node:22 npm testRun 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 buildFor Apple Silicon laptops and Graviton servers alike.
docker images / docker image lsLocal images
docker image history app:1.4.2Layer sizes of an imageFind the step that made it big.
docker inspect app --format '{{.State.Health.Status}}'Read one field of a container
docker stats --no-streamCPU, memory and I/O per container
docker system dfDisk used by images, containers, volumes and cache
docker system prune -a --volumesRemove everything unusedIncluding volumes with data; prune without -a --volumes is gentler.
docker builder pruneClear the build cacheOften the biggest item in system df.
docker cp app:/var/log/app.log .Copy files out of (or into) a container
docker network ls / inspectNetworks and who is attachedContainers on one user-defined network reach each other by name.
docker volume ls / inspectVolumes 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.2Push to a registrydocker login ghcr.io first.
docker save app:1.4.2 | gzip > app.tgzExport an image to a filedocker load < app.tgz on the other side.
docker restart appRestart a containerrestart: unless-stopped in Compose survives reboots.
docker update --memory 512m appChange a running container's limits
docker context use remoteRun Docker commands against another hostdocker 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.

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.

Share

Frequently asked questions

How do I see why a container exited?
docker ps -a shows the exit code, docker logs name shows its output, and docker inspect name shows State.OOMKilled if memory was the cause.
How do I remove unused Docker data safely?
docker system prune removes stopped containers, unused networks and dangling images. Adding -a removes unused images too, and --volumes deletes volumes, which may hold data.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools