Docker CLI Cheatsheet - Command Reference

All essential Docker commands organized by Image, Container, Network, Volume, Registry, Build Debug, and Compose. Copy and tweak on the spot during troubleshooting.

Containers & Orchestration·52 commands·Last updated 2026-07-21
Back to Containers & Orchestration

Image 8

docker images
List local images, add -a to include intermediate layers
docker pull nginx:alpine
Pull image with tag, defaults to latest if omitted
docker build -t app:1.0 .
Build and tag from Dockerfile in current dir
docker rmi <image>
Remove image, stop container first or use -f
docker tag app:1.0 reg/app:1.0
Tag image for registry push
docker save -o app.tar app:1.0
Export image as tar for offline transfer
docker load -i app.tar
Load image from tar file, useful in offline environments
docker pull alpine:3.20 --platform=linux/amd64
Pull image for a specific platform, e.g. amd64 on ARM Mac

Container 9

docker ps -a
List all containers including stopped
docker run -d -p 8080:80 --name web nginx
Run detached, map port, name container
docker exec -it web sh
Interactive shell into running container
docker logs -f --tail 100 web
Follow last 100 lines of container logs
docker stop web && docker rm web
Stop and remove container
docker inspect web
Full container config JSON for network/mount debugging
docker start web && docker restart web
Start or restart a stopped container
docker stats
Live CPU/memory/network I/O stats for all containers
docker top web
List running processes inside a container

Network & Volume 8

docker network ls
List networks, check here first for inter-container access
docker network create appnet
Create custom bridge network for name-based discovery
docker network connect appnet web
Connect a running container to a network
docker volume ls
List volumes
docker run -v data:/var/lib/app app
Mount named volume for persistence
docker run -v $(pwd):/app app
Bind mount current dir, common in dev
docker volume create appdata
Create a named volume for shared data
docker volume prune
Remove all unused volumes

Registry 6

docker login
Log in to Docker Hub, required before push
docker login registry.example.com
Log in to a private registry (Harbor/Registry)
docker push app:1.0
Push image to remote registry, must tag first
docker pull ubuntu:22.04
Pull Ubuntu 22.04 image from Docker Hub
docker search nginx
Search Docker Hub for official images
docker logout
Log out from the current registry

Build & Debug 7

docker build -t app:1.0 --no-cache .
Force rebuild without cache layers
docker build -t app:1.0 --target=dev .
Build only up to a specific multi-stage target
docker history app:1.0
View image build history, layer sizes and commands
docker diff <container>
Inspect filesystem changes in a container
docker cp app.conf web:/etc/nginx/conf.d/
Copy local config file into a container
docker cp web:/var/log/nginx/access.log ./
Copy a log file from a container to local
docker events --since 5m
Stream Docker daemon events in real time

Compose & Cleanup 9

docker compose up -d
Start Compose project in background
docker compose logs -f svc
Follow logs for a specific service
docker compose down
Stop and remove containers, networks; add -v for volumes
docker compose ps
List container status for all services in Compose project
docker compose restart
Restart all or specified services
docker system df
Check disk usage by images/containers/volumes
docker system prune -a
Clean all unused images and containers, use -a with caution
docker container prune
Remove all stopped containers
docker image prune -a
Remove all unused images to free disk space

FAQ 5

Q: How to clean up all unused Docker resources?
A: docker system prune -a removes all unused images, containers, networks, and build cache. Add --volumes to also remove volumes.
Q: How to view container logs?
A: docker logs <container> shows full logs, add -f to follow, --tail 50 for last 50 lines, --since 5m for last 5 minutes.
Q: How to enter a running container?
A: docker exec -it <container> /bin/bash (or /bin/sh). Exit with exit or Ctrl+D.
Q: How to copy files between host and container?
A: docker cp <src> <container>:<dest> to copy in, docker cp <container>:<src> <dest> to copy out.
Q: What restart policies are available?
A: --restart=no (default)/on-failure/always/unless-stopped. unless-stopped is common for production.

💡 Tips

  • In docker run -p, it's host_port:container_port — reversing them blocks external access.
  • If exec says "executable file not found", switch to sh: Alpine images usually lack bash.
  • prune -a removes all images not used by any container — verify with docker images first on production.
  • docker system df quickly shows disk usage — run it periodically to avoid /var/lib/docker filling up.
  • docker compose restart is faster than down/up and does not rebuild networks or volumes — best for nginx config changes.

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Found an error? Report it

Wrong command or description? Open an issue to help us fix it.

Found an error? Report it