Docker Commands Cheat Sheet (Beginner → Pro Guide)

If you're learning DevOps, backend, or cloud, mastering Docker commands is non-negotiable.
This guide covers all essential Docker commands you’ll actually use in real projects — not just theory.
🧠 Why Docker Commands Matter
Docker helps you:
Package your app
Run it anywhere
Deploy faster
But to do that, you need to know how to control Docker using CLI
1. Docker Image Commands
These commands deal with images (blueprints of your app)
docker images # List all images
docker build -t app . # Build image from Dockerfile
docker pull nginx # Download image from Docker Hub
docker rmi image_id # Remove image
Example:
docker build -t myapp .
2. Container Commands
Containers are running instances of images
docker run nginx # Run container
docker run -it ubuntu /bin/bash # Interactive container
docker run -d nginx # Run in background
docker ps # Running containers
docker ps -a # All containers
docker stop <id> # Stop container
docker start <id> # Start container
docker restart <id> # Restart container
docker rm <id> # Remove container
3. Debugging & Inspection
These commands help you debug like a pro
docker logs <id> # View logs
docker exec -it <id> bash # Enter container
docker inspect <id> # Detailed info
docker stats #Live resource usage
Real-world use:
Debug why your app is crashing
4. Networking Commands
Used when multiple containers communicate
docker network ls #List networks
docker network create mynet #Create a network
docker network rm mynet #Remove a network
docker network connect mynet #Connect container to network
Example:
- Backend ↔ Database connection
5. Volume Commands (Data Persistence)
docker volume ls #List volumes
docker volume create myvol #Create a volume
docker volume inspect myvol #Inspect the container
docker volume rm myvol #Remove a volume
docker run -v <vol>:/path ubuntu #Mount volume to container
Why important:
Containers are temporary, volumes store permanent data
6. Port & Environment Variables
docker run -p 3000:3000 nginx #Map host port to container port
docker run -e PORT=3000 app #Run the container
docker run --env-file .env app #Load env from file
Used for:
Exposing apps
Configuring DB connections
7. Docker Hub Commands
docker login #Login to Docker Hub
docker tag app username/app:latest #Tag for push
docker push username/app:latest #Push image to Hub
docker pull username/app:latest #Pull image from Hub
Flow:
Build → Tag → Push → Pull
8. Cleanup Commands
docker system prune -a #Remove all unused data
docker container prune #Remove stopped containers
docker volume prune #Remove unused volumes
docker network prune #Remove unused images
docker image prune #Remove unused images
Keeps your system clean
9. Docker Compose Commands
Used for multi-container apps
docker-compose up
docker-compose up -d
docker-compose down
docker-compose build
Example:
Node + MongoDB
Full-stack apps
Real DevOps Workflow
Code → Dockerfile → Image → Container → Docker Hub → Deployment
Final Thoughts
Docker is not about memorizing commands.
It’s about understanding:
How apps run
How systems connect
How deployments work
Pro Tip
Instead of memorizing:
👉 Build 1 real project using:
Docker
Compose
AWS
That’s where real learning happens 🚀
📌 One-Line Summary
Docker commands help you build, run, manage, and deploy applications efficiently.
If you found this helpful, you’re already ahead of many beginners 🔥
Keep building — that’s how you become unstoppable.



