Docker Cheat Sheet
The commands I actually use, grouped by job. Use the variables input to swap placeholders like IMAGE_NAME or CONTAINER_NAME across every example.
Docker has a wide CLI surface but the part you actually use day to day is small. This is the working set I reach for: images, container lifecycle, run flags, exec and logs, build, networks, volumes, Compose, registry, and the prune commands that keep a host from filling up. Generic placeholders like IMAGE_NAME, CONTAINER_NAME, HOST_PORT, VOLUME_NAME are swappable from the input above the cheat sheet, so you can type IMAGE_NAME=postgres:16, HOST_PORT=5432 and every example below updates in place.
For the longer-form pieces (writing a Dockerfile, Compose, multi-stage builds, troubleshooting), see the linked articles in the What to do next section.
What to do next
For the longer-form pieces this cheat sheet references:
- How to Install Docker on Ubuntu, macOS, and Windows: the install paths per OS.
- docker run Cheat Sheet: every
docker runflag worth knowing, with patterns. - How to Write a Dockerfile:
FROM,COPY,RUN,CMD,ENTRYPOINT, and the layer-cache rules that decide build speed. - Docker Compose: Getting Started: a working
docker-compose.ymlwalkthrough. - docker exec and docker logs: the two commands you reach for hourly.
- Docker Container Lifecycle: ps, stop, start, restart, rm: managing the containers you have.
- docker system prune: Free Disk Space Used by Docker: when Docker is eating your disk.
- How to Run Anything on Your Computer Without Installing It: the hub for the per-tool recipes (MySQL, PostgreSQL, Redis, MongoDB, Elasticsearch, Nginx, WordPress, PHP, and more).
FAQ
docker --help lists every subcommand and flag. This page is the working set: the ones I actually reach for, with the flags that matter and short notes on the gotchas. You will look at --help a handful of times a year for the rare flags; this page is what you have open on the second monitor while you work.
It accepts a comma-separated list like IMAGE_NAME=postgres:16, CONTAINER_NAME=db, HOST_PORT=5432. Every occurrence of those tokens in the examples below the input is swapped on the fly. Useful when you want to copy commands without doing the mental find-replace.
Stored in your browser's localStorage, not on the server. Clear it with the button next to the input.
docker compose (space). Compose V2 has been the default since 2022, and the standalone docker-compose binary was removed from official packages mid-2024. The commands and the file format are otherwise the same; the version: key at the top of docker-compose.yml is no longer required and is warned-about in current Compose. See Docker Compose: Getting Started.
docker system prune sweeps stopped containers, unused networks, dangling images, and build cache in one pass. -a extends that to all unused images. --volumes extends it to unused volumes, that flag is the data-loss one. The individual docker image prune, docker container prune, docker volume prune, docker network prune, and docker builder prune let you scope the cleanup. Full breakdown in docker system prune: Free Disk Space.
You are running an x86 image under QEMU emulation. Use --platform linux/arm64 if the image publishes an arm64 manifest, or accept the emulation hit. docker manifest inspect IMAGE_NAME shows which platforms the image supports. The full story is in "exec format error", Apple Silicon and Multi-Architecture Docker Images.
Sources
Authoritative references this article was fact-checked against.
- Docker CLI reference (docs.docker.com)docs.docker.com
- Docker Compose CLI referencedocs.docker.com
- BuildKit documentationdocs.docker.com





