Docker Commands Cheat Sheet
If you use Docker long enough, you eventually hit the same wall:
-
Containers are running… but nothing works
-
Logs are empty or useless
-
You forget the exact command to “just get inside the thing”
-
Disk space mysteriously vanishes
This Docker cheat sheet isn’t a full reference manual.
It’s the 90% of Docker commands you’ll actually use, written in plain English, so you can move fast when something breaks.
Bookmark it. You’ll be back.
Docker Mental Model (30-Second Primer)
Before commands, anchor these concepts:
-
Image → A blueprint (read-only)
-
Container → A running (or stopped) instance of an image
-
Volume → Persistent data outside container lifecycle
-
Network → How containers talk to each other
-
Dockerfile → Instructions to build an image
-
Docker Compose → Runs multi-container apps
If this mental model clicks, Docker becomes predictable instead of frustrating.
Container Lifecycle Commands
docker run
Create and start a new container.
Most-used flags:
-
-d→ run in background -
-p 8080:80→ map ports -
--name myapp→ name container -
-v host:container→ mount volume -
--env KEY=value→ environment variable
Example:
docker start
Start an existing container.
docker stop
Gracefully stop a container.
docker restart
Quick reset (stop + start).
docker rm
Delete a container (must be stopped).
Force remove:
Inspecting & Debugging Containers
docker ps
List running containers.
Include stopped containers:
docker logs
View container output.
Follow logs:
docker exec
Run a command inside a running container.
If bash doesn’t exist (Alpine images):
This is your “open the sealed box” command.
docker inspect
View detailed container configuration.
Common uses:
-
Find container IP
-
Check mounted volumes
-
Confirm environment variables
-
Debug port bindings
Image Commands
docker images
List local images.
docker pull
Download an image.
docker build
Build an image from a Dockerfile.
docker rmi
Remove an image.
Force:
Volumes & Persistent Data
docker volume ls
List volumes.
docker volume inspect
See where data lives on disk.
docker volume rm
Delete a volume.
⚠️ This deletes data permanently.
Networking Commands
docker network ls
List networks.
docker network inspect
See connected containers.
docker network create
Create a custom network.
Custom networks = cleaner container-to-container communication.
Docker Cleanup Commands
docker system df
Check disk usage.
docker system prune
Remove unused containers, images, and networks.
Aggressive cleanup:
If Docker is eating your disk space, this is usually the fix.
Docker Compose Cheat Sheet
docker compose up
Start all services.
Detached:
docker compose down
Stop and remove everything.
Remove volumes too:
docker compose ps
List running services.
docker compose logs
View service logs.
docker compose exec
Run a command inside a service.
Docker Debugging Shortcuts (Memorize These)
-
Container won’t start? →
docker logs -
Need shell access? →
docker exec -it -
Port not working? →
docker inspect -
Disk full? →
docker system prune -
Data missing? → check volumes
-
Multiple containers? → Docker Compose
Final Thought
Docker isn’t hard.
It’s just unforgiving when you don’t know which command unlocks which door.
This cheat sheet covers the commands that matter—the ones you’ll actually use under pressure.
