All Articles
Docker Commands Cheat Sheet 2026 — Complete Reference for DevOps
By Jay, editor · Every shortcut on this site is verified by hand against official documentation · Updated July 2026
Published: March 20, 2026 · Updated: May 1, 2026 · 12 min read
Docker is the standard for packaging and running applications in containers. This cheat sheet covers every command you need in production — from basic container management to Docker Compose and system cleanup.
1. Container Management
| Command | What it does |
| docker ps | List running containers |
| docker ps -a | List all containers including stopped |
| docker run -d --name my-app -p 8080:80 <image> | Run detached with name and port mapping |
| docker run -it <image> bash | Run with interactive terminal |
| docker run --rm <image> | Auto-remove container when it exits |
| docker run -e KEY=value <image> | Set environment variable |
| docker run -v /host/path:/container/path <image> | Mount a host directory as volume |
| docker start / stop / restart <container> | Start, stop, or restart a container |
| docker kill <container> | Immediately force-stop (SIGKILL) |
| docker rm <container> | Remove a stopped container |
| docker rm -f <container> | Force-remove a running container |
| docker exec -it <container> bash | Open shell inside running container |
| docker inspect <container> | Show detailed container info (JSON) |
| docker cp <container>:/path ./local | Copy file from container to host |
| docker stats | Live CPU/memory/network usage |
Tip: Stop all running containers at once: docker stop $(docker ps -q)
2. Image Commands
| Command | What it does |
| docker images | List local images |
| docker pull <image>:<tag> | Download image from registry |
| docker rmi <image> | Remove a local image |
| docker tag <image> <new-name>:<tag> | Tag an image with a new name |
| docker history <image> | Show image layer history |
| docker save -o image.tar <image> | Export image to tar file |
| docker load -i image.tar | Load image from tar file |
3. Volumes
| Command | What it does |
| docker volume ls | List all volumes |
| docker volume create <name> | Create a named volume |
| docker volume inspect <name> | Show volume details |
| docker volume rm <name> | Remove a volume |
| docker volume prune | Remove all unused volumes |
| docker run -v my-vol:/app/data <image> | Mount named volume into container |
4. Networks
| Command | What it does |
| docker network ls | List all networks |
| docker network create <name> | Create a custom bridge network |
| docker network connect <network> <container> | Connect container to a network |
| docker network disconnect <network> <container> | Disconnect container from network |
| docker network prune | Remove all unused networks |
| docker run --network host <image> | Use host network directly (no NAT) |
5. Docker Compose
Docker Compose manages multi-container applications defined in docker-compose.yml.
| Command | What it does |
| docker compose up -d | Start all services in background |
| docker compose up --build | Rebuild images before starting |
| docker compose down | Stop and remove containers and networks |
| docker compose down -v | Also remove volumes |
| docker compose ps | List service containers |
| docker compose logs -f <service> | Follow logs for a specific service |
| docker compose exec <service> bash | Open shell in a running service |
| docker compose restart <service> | Restart a specific service |
| docker compose pull | Pull latest images for all services |
| docker compose run <service> <cmd> | Run a one-off command in a service |
| docker compose config | Validate and view merged compose config |
6. Logs & Monitoring
| Command | What it does |
| docker logs -f <container> | Follow log output in real time |
| docker logs --tail 100 <container> | Show last 100 log lines |
| docker logs --since 1h <container> | Show logs from last hour |
| docker stats <container> | Resource usage for specific container |
| docker events | Stream real-time Docker daemon events |
7. Building Images
| Command | What it does |
| docker build -t myapp:1.0 . | Build and tag from current directory |
| docker build -f Dockerfile.prod . | Build using a specific Dockerfile |
| docker build --no-cache . | Build without cache (fresh build) |
| docker build --build-arg KEY=val . | Pass build-time variable |
| docker build --target <stage> . | Build up to a specific multi-stage target |
Multi-stage builds reduce final image size by separating build dependencies from runtime. Use --target to build only specific stages during development.
8. Registry & Pushing
| Command | What it does |
| docker login | Log in to Docker Hub |
| docker login <registry-url> | Log in to a private registry |
| docker tag myapp:1.0 myuser/myapp:1.0 | Tag image for Docker Hub |
| docker push myuser/myapp:1.0 | Push image to Docker Hub |
| docker search nginx | Search Docker Hub for images |
9. System Cleanup
| Command | What it does |
| docker system df | Show disk usage by Docker |
| docker system prune | Remove stopped containers, dangling images, unused networks |
| docker system prune -a | Also remove all unused images |
| docker system prune -a --volumes | Full cleanup including volumes |
| docker container prune | Remove all stopped containers |
| docker image prune -a | Remove all unused images |
| docker builder prune | Clear build cache |
Warning: docker system prune -a --volumes removes everything unused including named volumes. Back up data before running in production.
10. Power Tips & One-liners
| Command | What it does |
| docker stop $(docker ps -q) | Stop all running containers |
| docker rm $(docker ps -aq) | Remove all stopped containers |
| docker rmi $(docker images -q) | Remove all local images |
| docker run --rm -it alpine sh | Quick throwaway Alpine shell |
| docker inspect -f "{{.NetworkSettings.IPAddress}}" <c> | Get container IP address |
| docker run --memory 512m --cpus 1.5 <image> | Limit container resources |
| docker diff <container> | Show changed files vs the original image |
| docker commit <container> my-snapshot | Save container state as a new image |
Also explore: Docker CLI shortcuts and DevOps tools
View Docker Shortcuts Reference
How to read the sections
The commands are grouped by what they act on — containers, images, volumes, networks, Compose — which matches how Docker's own CLI is organised (docker container, docker image). The short forms most people type (docker ps, docker rm) are aliases of those, and both forms appear where the difference matters. Placeholders in brackets are values to replace; everything else is literal.
Three habits the sheet cannot teach
First, name containers and networks; --name on run turns every later command from an ID lookup into a word. Second, keep state in named volumes, not in the container, so docker rm is never a data-loss event. Third, read docker system df before pruning, because the cleanup commands delete exactly what they say and Docker Desktop's disk image does not shrink on its own. The Docker reference page on this site explains the flags behind each of these.
Compose versus plain docker
Anything with more than one container belongs in a compose.yaml, and the Compose section of the sheet replaces most of the run-and-network commands above it: docker compose up -d creates the network, volumes and containers from the file, and down removes them together. The plain commands remain the tools for inspecting what Compose created.