Docker CLI Cheat Sheet
Images
# Build
docker build -t myapp:latest .
docker build -t myapp:v1.0 -f Dockerfile.prod .
docker build --no-cache -t myapp:latest .
# List & manage
docker images
docker image ls --filter "dangling=true"
docker image prune -a # Remove unused images
docker rmi myapp:latest
# Pull & push
docker pull nginx:1.25-alpine
docker tag myapp:latest registry.com/myapp:v1.0
docker push registry.com/myapp:v1.0
Containers
# Run
docker run -d --name myapp -p 8080:80 myapp:latest
docker run -it --rm ubuntu:22.04 bash # Interactive, auto-remove
docker run -d -v ./data:/app/data myapp:latest
docker run -d --env-file .env myapp:latest
docker run -d --restart=unless-stopped myapp:latest
# Manage
docker ps # Running
docker ps -a # All (including stopped)
docker stop myapp
docker start myapp
docker restart myapp
docker rm myapp
docker rm $(docker ps -aq) # Remove all stopped
# Interact
docker exec -it myapp bash
docker logs myapp
docker logs -f --tail 100 myapp # Follow last 100 lines
docker cp myapp:/app/config.json ./config.json
Volumes
docker volume create mydata
docker volume ls
docker volume inspect mydata
docker volume rm mydata
docker volume prune # Remove unused
Networks
docker network create mynet
docker network ls
docker network connect mynet myapp
docker network disconnect mynet myapp
docker network inspect mynet
Docker Compose
docker compose up -d
docker compose down
docker compose logs -f
docker compose ps
docker compose exec app bash
docker compose build --no-cache
docker compose pull
docker compose restart app
Cleanup
# Nuclear option — reclaim ALL space
docker system prune -a --volumes
# Selective cleanup
docker container prune # Stopped containers
docker image prune -a # Unused images
docker volume prune # Unused volumes
docker builder prune # Build cache
# Check disk usage
docker system df
Debugging
# Inspect container details
docker inspect myapp
docker inspect --format='{{.State.Health.Status}}' myapp
docker inspect --format='{{.NetworkSettings.IPAddress}}' myapp
# Resource usage
docker stats
docker stats myapp --no-stream
# History of an image
docker history myapp:latest
# View running processes inside a container
docker top myapp
# Show port mappings
docker port myapp
# Stream container events in real time
docker events --filter container=myapp
# Export container filesystem as tar archive
docker export myapp > myapp-fs.tar
# Show changes to files in container
docker diff myapp
Multi-Platform Builds
# Create a buildx builder
docker buildx create --name multiarch --use
# Build for multiple architectures
docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest --push .
# Inspect build cache
docker buildx du
# List available builders
docker buildx ls
Registry & Authentication
# Log in to a registry
docker login registry.com
docker login ghcr.io -u USERNAME --password-stdin
# Log out
docker logout registry.com
# Search Docker Hub
docker search nginx --limit 5
# Save and load images as tar files
docker save myapp:latest -o myapp.tar
docker load -i myapp.tar
Resource Constraints
# Run with memory and CPU limits
docker run -d --memory=512m --cpus=1.5 myapp:latest
# Update limits on a running container
docker update --memory=1g --cpus=2 myapp
# Run with a specific restart policy
docker run -d --restart=on-failure:5 myapp:latest
Related Articles
Was this article helpful?
CI/CD Engineering Lead
Automation evangelist who believes no deployment should require a human. I write pipelines, break pipelines, and write about both. Code-first, always.
Related Articles
AWS CLI: Cheat Sheet
AWS CLI cheat sheet with copy-paste commands for EC2, S3, IAM, Lambda, ECS, CloudFormation, SSM, and Secrets Manager operations.
Terraform CLI: Cheat Sheet
Terraform CLI cheat sheet with commands organized by workflow — init, plan, apply, destroy, state manipulation, imports, and workspace management.
Docker Multi-Stage Builds for Production-Ready Minimal Images
Shrink Docker images from 1.2GB to 45MB using multi-stage builds. Production Dockerfiles for Node.js, Go, and Python with real size comparisons.
Docker "Permission Denied" On Mounted Volumes: Fix Unix Socket And File Ownership Errors
If you've spent more than five minutes with Docker volumes, you've seen it. That infuriating wall of red text: Or worse, the cryptic Unix socket variant: Y...
Reducing Docker Image Build Times With BuildKit Cache Mounts
If your Docker builds are slow, cache mounts are probably the single highest-leverage fix available. I've seen Node.js image builds drop from 4 minutes to...
Fix Docker Container DNS Resolution Failures
Resolve DNS lookup failures inside Docker containers — fix resolv.conf, custom networks, and upstream DNS configuration issues.
More in Docker
View all →Fix Docker 'No Space Left on Device' Error
Reclaim disk space when Docker fills your drive — clean up dangling images, stopped containers, unused volumes, and build cache.
Docker Multi-Stage Builds: Shrink Images by 80% for Production
Cut Docker image sizes by up to 80% using multi-stage builds — practical patterns for Go, Node.js, and Python apps in production.