Docker commands cheatsheet.
Build images, run containers, and use Compose — the Docker commands you actually need. Tap to copy.
docker pull <image>Download an image from a registrydocker build -t <name> .Build an image from the Dockerfile heredocker imagesList local imagesdocker rmi <image>Remove an imagedocker run <image>Create and start a container from an imagedocker run -d -p 8080:80 <image>Run detached and map a portdocker psList running containersdocker ps -aList all containers, including stoppeddocker stop <id>Stop a running containerdocker rm <id>Remove a stopped containerdocker exec -it <id> bashOpen an interactive shell in a containerdocker logs -f <id>Stream a container's logsdocker compose upStart the services in docker-compose.ymldocker compose up -dStart services in the backgrounddocker compose downStop and remove the compose servicesdocker compose buildBuild or rebuild compose servicesdocker compose logs -fFollow logs for all servicesdocker system pruneRemove unused containers, networks and imagesdocker volume lsList volumesdocker network lsList networksThe core loop
Docker has a lot of subcommands, but daily work revolves around a short cycle: build an image from a Dockerfile, run a container from that image, and ps to see what's running. The mental model that makes Docker click: an image is a frozen snapshot of an app and everything it needs, and a container is a running instance of that image. Once that distinction is clear, the commands stop feeling arbitrary.
Getting inside and debugging
The commands people reach for when something's wrong are worth knowing cold. docker logs <id> shows a container's output, and docker exec -it <id> bash drops you into a shell inside a running container so you can poke around as if you'd SSH'd in. docker ps -a reveals stopped containers too, which is often where the clue to a crash is hiding. These three turn Docker from a black box into something you can inspect.
Compose and cleanup
For anything with more than one moving part — an app plus a database, say — docker compose up -d brings the whole stack up in the background from a single YAML file, and docker compose down tears it back down. One housekeeping note: images, stopped containers and volumes pile up and quietly eat disk space, so docker system prune is the periodic cleanup worth remembering. These pair naturally with the kubectl commands when you move from single containers to orchestration, and the Linux commands for everything around them.