Docker has a large surface area and you use maybe fifteen commands of it regularly. Here's the working set, plus the two things that trip people up: getting inside a container to debug it, and reclaiming the disk space Docker quietly eats.
| Command | What it does |
|---|---|
| docker run -d --name web -p 8080:80 nginx | Run detached, named, host port 8080 → container port 80 |
| docker run -it --rm ubuntu bash | Interactive throwaway shell — --rm deletes it on exit |
| docker ps | What's running |
| docker ps -a | Everything, including stopped — where "why is that name taken" gets answered |
| docker stop web / docker start web | Stop or start by name |
| docker rm web | Delete a stopped container |
Port mapping is always -p HOST:CONTAINER. Getting it backwards is the most common Docker mistake there is.
| Command | What it does |
|---|---|
| docker logs -f web | Follow the logs. Start here, always. |
| docker logs --tail 100 web | Last 100 lines |
| docker exec -it web sh | Get a shell inside a running container. Use bash if the image has it. |
| docker inspect web | Full config — networks, mounts, env, IP |
| docker stats | Live CPU/memory per container |
| docker diff web | What files changed since the image — surprisingly useful |
docker ps -a (is it even running, or crash-looping?) → docker logs (what did it say on the way down?) → docker exec (go look inside). Ninety percent of problems are answered by step two.| Command | What it does |
|---|---|
| docker images | What's on disk |
| docker pull nginx:1.27 | Fetch a specific tag — pin versions, don't rely on latest |
| docker build -t myapp:1.0 . | Build from the Dockerfile here |
| docker rmi image_id | Delete an image |
| docker history myapp:1.0 | See the layers — good for finding what bloated your image |
Docker accumulates stopped containers, dangling images, unused volumes, and build cache until a disk fills up and something unrelated breaks.
| Command | What it does |
|---|---|
| docker system df | What Docker is using, by category. Run this first. |
| docker system prune | Remove stopped containers, unused networks, dangling images |
| docker system prune -a --volumes | Aggressive — also removes unused images and volumes |
--volumes deletes unused volumes, and "unused" includes the database volume of a container you happen to have stopped. Check docker volume ls before you run it on anything you care about.| Command | What it does |
|---|---|
| docker compose up -d | Start the whole stack in the background |
| docker compose down | Stop and remove it (add -v to drop volumes too) |
| docker compose logs -f svc | Follow one service's logs |
| docker compose ps | Status of the stack |
| docker compose exec svc sh | Shell into a service |
| docker compose up -d --build | Rebuild images then start — after you change a Dockerfile |
| docker compose restart svc | Bounce one service |
Note it's docker compose (a subcommand) on current versions, not the old standalone docker-compose binary. Both may work; the space is the modern one.
The Docker & Compose Cheat Sheet — one clean page, made to print and keep next to the keyboard. Instant download.
Get the sheet — $3 →Pairs with the Linux commands sheet — most of what you do inside a container is plain Linux — and the ports reference when you're untangling what's bound where.