Docker Cheatsheet
Searchable reference of 84 essential Docker commands covering containers, images, volumes, networks, compose, and debugging.
84 commands found
Container Lifecycle
Create and start a container
docker run -d -p 8080:80 --name web nginx:alpineCreate a container without starting
docker create --name myapp node:20-alpineStart a stopped container
docker start myappGracefully stop a running container
docker stop myappRestart a container
docker restart myappForce stop a container (SIGKILL)
docker kill myappRemove a stopped container
docker rm myappForce remove a running container
docker rm -f myappPause all processes in a container
docker pause myappUnpause a paused container
docker unpause myappRename a container
docker rename old_name new_nameBlock until container stops, print exit code
docker wait myappList running containers
docker ps --format 'table {{.Names}}\t{{.Status}}'List all containers (including stopped)
docker ps -a --filter status=exitedRun and auto-remove on exit
docker run --rm -it alpine shImages
Build image from Dockerfile
docker build -t myapp:v1.0 .Build without using cache
docker build --no-cache -t myapp:latest .List local images
docker images --format '{{.Repository}}:{{.Tag}} {{.Size}}'Remove an image
docker rmi myapp:v1.0Tag an image
docker tag myapp:latest registry.io/myapp:v1.0Pull image from registry
docker pull nginx:alpinePush image to registry
docker push registry.io/myapp:v1.0Save image to tar archive
docker save -o myapp.tar myapp:latestLoad image from tar archive
docker load -i myapp.tarShow image layer history
docker history --no-trunc myapp:latestShow detailed image/container info
docker inspect --format '{{.Config.Env}}' myappRemove unused images
docker image prune -a --filter 'until=24h'Volumes
Create a named volume
docker volume create pgdataList all volumes
docker volume ls --filter dangling=trueShow volume details
docker volume inspect pgdataRemove a volume
docker volume rm pgdataRemove all unused volumes
docker volume prune -fMount a volume to container
docker run -v pgdata:/var/lib/postgresql/data postgres:16Mount with explicit options
docker run --mount type=bind,src=./app,dst=/app node:20Copy files between container and host
docker cp myapp:/app/logs ./logsNetworks
Create a network
docker network create --driver bridge mynetList networks
docker network lsShow network details
docker network inspect bridgeConnect container to network
docker network connect mynet myappDisconnect container from network
docker network disconnect mynet myappRemove a network
docker network rm mynetRemove unused networks
docker network prune -fRun container in specific network
docker run --network mynet --name api myapp:latestCompose
Start all services
docker compose up -d --buildStop and remove containers
docker compose down --volumes --remove-orphansList compose services
docker compose ps --format jsonView service logs
docker compose logs -f --tail=100 apiBuild or rebuild services
docker compose build --no-cache apiPull service images
docker compose pullExecute command in running service
docker compose exec db psql -U postgresRun one-off command
docker compose run --rm api npm testRestart services
docker compose restart api workerValidate and view config
docker compose config --servicesScale a service
docker compose up -d --scale worker=3System/Cleanup
Show Docker disk usage
docker system df -vRemove all unused data
docker system prune -a --volumes -fRemove all stopped containers
docker container prune -fRemove all unused images
docker image prune -a -fRemove build cache
docker builder prune --all -fDisplay system-wide information
docker system info --format '{{.ServerVersion}}'Get real-time events
docker system events --filter type=containerLive resource usage statistics
docker stats --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}'Show total disk usage breakdown
docker system df --format '{{.Type}}: {{.Size}}'Manage Docker contexts
docker context lsDebugging
View container logs
docker logs -f --tail=50 myappRun command in running container
docker exec -it myapp /bin/shAttach to running container
docker attach myappDisplay running processes
docker top myappList port mappings
docker port myappShow filesystem changes
docker diff myappShow container details
docker inspect --format '{{.State.Status}}' myappView logs since timestamp
docker logs --since 2h myappMonitor Docker events
docker events --filter container=myappCheck environment variables
docker exec myapp env | sortCheck listening ports inside container
docker exec myapp netstat -tlnpCheck container IP address
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' myappRegistry
Log in to a registry
docker login registry.io -u usernameLog out from a registry
docker logout registry.ioSearch Docker Hub
docker search --filter is-official=true nginxInspect image manifest
docker manifest inspect nginx:alpineBuild multi-platform image
docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest --push .List builder instances
docker buildx lsTag and push to ECR/GCR/ACR
docker tag app:v1 123456.dkr.ecr.us-east-1.amazonaws.com/app:v1Pull specific platform image
docker pull --platform linux/arm64 nginx:alpineWhat is Docker?
Docker is a platform for building, shipping, and running applications in containers. Containers package an application with all its dependencies into a standardized unit, ensuring it runs identically across development, staging, and production environments. Docker has become the industry standard for containerization and is fundamental to modern DevOps workflows, CI/CD pipelines, and microservices architectures.
This Docker cheatsheet covers the most commonly used commands organized by workflow: managing container lifecycles, building and managing images, working with volumes and networks, orchestrating with Docker Compose, cleaning up resources, debugging issues, and interacting with registries. Whether you are a beginner learning Docker or an experienced DevOps engineer looking for quick reference, these commands cover the full spectrum of daily Docker operations.
Frequently Asked Questions
How to remove all Docker images?
Use docker image prune -a -f to remove all images not associated with a running container. To remove absolutely everything including volumes and networks, use docker system prune -a --volumes -f. Be careful in production—this removes all cached layers and will require re-pulling images. To remove specific images, use docker rmi image:tag or filter with docker images --filter dangling=true -q | xargs docker rmi.
How to enter a running container?
Use docker exec -it container_name /bin/sh (or /bin/bash if available) to get an interactive shell inside a running container. The -i flag keeps STDIN open and -t allocates a pseudo-TTY. For distroless or minimal images without a shell, use docker debug (Docker Desktop) or attach an ephemeral debug container with kubectl debug in Kubernetes environments.
How to check Docker disk usage?
Use docker system df to see disk usage broken down by images, containers, volumes, and build cache. Add -v for detailed per-item breakdown. Common culprits for high disk usage are dangling images (intermediate build layers), stopped containers with large logs, unused volumes, and build cache. Use docker system prune to reclaim space, or target specific resources with docker image prune, docker container prune, or docker volume prune.