Docker Cheat Sheet: Day-to-Day Commands
Essential Docker commands for everyday use. Quick reference for container management, cleanup, and common operations.
Moshiour Rahman
Advertisement
Overview
This is a collection of Docker commands I use daily. Bookmark this page as a quick reference guide for container management and cleanup operations.
Container Management
Stop All Running Containers
Use docker container stop with a list of all container IDs:
docker container stop $(docker container ls -aq)
This command:
docker container ls -aq- Lists all container IDs (running and stopped)- Passes them to
docker container stop
Remove All Containers
Force remove all containers (running and stopped):
docker rm $(docker ps -aq) -f
Flags:
-a- All containers (not just running)-q- Quiet mode (only IDs)-f- Force removal (even if running)
Volume Management
Remove All Unused Volumes
After removing containers, clean up orphaned volumes:
docker volume prune
You’ll be prompted to confirm. Use -f to skip the prompt:
docker volume prune -f
List and Remove Specific Volumes
# List all volumes
docker volume ls
# Remove a specific volume
docker volume rm volume_name
# Remove multiple volumes
docker volume rm volume1 volume2 volume3
System Cleanup
Remove All Unused Objects
The nuclear option - removes stopped containers, unused networks, and dangling images:
docker system prune
Output:
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N]
Include Unused Volumes
Add --volumes to also remove unused volumes:
docker system prune --volumes
Force Without Confirmation
docker system prune -af --volumes
Flags:
-a- Remove all unused images (not just dangling)-f- Force (no confirmation prompt)--volumes- Include unused volumes
Image Management
Remove Dangling Images
Dangling images are layers with no tags and not referenced by any container:
docker image prune
Remove All Unused Images
docker image prune -a
List Images by Size
docker images --format "{{.Repository}}:{{.Tag}} - {{.Size}}" | sort -k2 -h
Container Logs
View Container Logs
# View all logs
docker logs container_name
# Follow logs (like tail -f)
docker logs -f container_name
# Last 100 lines
docker logs --tail 100 container_name
# Logs since a time
docker logs --since 2h container_name
Quick Reference Table
| Command | Description |
|---|---|
docker ps | List running containers |
docker ps -a | List all containers |
docker images | List images |
docker volume ls | List volumes |
docker network ls | List networks |
docker stats | Live resource usage |
docker top container | Running processes in container |
docker inspect container | Detailed container info |
Docker Compose Commands
Start Services
# Start in foreground
docker-compose up
# Start in background
docker-compose up -d
# Rebuild and start
docker-compose up --build
Stop Services
# Stop services
docker-compose down
# Stop and remove volumes
docker-compose down -v
# Stop and remove images
docker-compose down --rmi all
View Logs
# All services
docker-compose logs
# Specific service
docker-compose logs service_name
# Follow logs
docker-compose logs -f
Useful Aliases
Add these to your .bashrc or .zshrc:
# Docker
alias dps='docker ps'
alias dpsa='docker ps -a'
alias dimg='docker images'
alias dexec='docker exec -it'
alias dlogs='docker logs -f'
alias dprune='docker system prune -af'
# Docker Compose
alias dc='docker-compose'
alias dcup='docker-compose up -d'
alias dcdown='docker-compose down'
alias dclogs='docker-compose logs -f'
Conclusion
These commands cover most day-to-day Docker operations. Keep this page bookmarked for quick reference!
Pro Tips:
- Always be careful with
prunecommands in production - Use
--dry-runwhen available to preview changes - Regularly clean up to save disk space
Advertisement
Moshiour Rahman
Software Architect & AI Engineer
Enterprise software architect with deep expertise in financial systems, distributed architecture, and AI-powered applications. Building large-scale systems at Fortune 500 companies. Specializing in LLM orchestration, multi-agent systems, and cloud-native solutions. I share battle-tested patterns from real enterprise projects.
Related Articles
Docker Compose for Microservices: Complete Development Guide
Master Docker Compose for local microservices development. Learn multi-container orchestration, networking, volumes, and production-ready configurations.
DevOpsDocker Compose Tutorial: Building Multi-Container Applications
Master Docker Compose for multi-container applications. Learn to define, configure, and run complex application stacks with practical examples including web apps with databases.
DevOpsDocker Best Practices for Production: Complete Guide
Master Docker best practices for production deployments. Learn image optimization, security hardening, multi-stage builds, and container orchestration.
Comments
Comments are powered by GitHub Discussions.
Configure Giscus at giscus.app to enable comments.