10 Docker Commands Every Developer Should Know in 2026
1. docker exec -it - Your Debug Entry Point
The classic. But most people don't use it right. Always specify the shell explicitly:
docker exec -it my-container /bin/bash
Alpine containers don't have bash:
docker exec -it my-container /bin/sh
Bonus: pipe commands directly without entering the container:
docker exec my-container cat /etc/nginx/nginx.conf
2. docker logs - Read the Room
Don't SSH into a container to read logs. Use the tools built for it:
docker logs --tail 100 -f my-container # last 100 lines, follow
docker logs --since 10m my-container # last 10 minutes
docker logs --timestamps my-container # show when each line happened
3. docker system df - Where Did My Disk Go?
This single command tells you exactly how much space Docker is eating:
docker system df
| TYPE | TOTAL | ACTIVE | SIZE | RECLAIMABLE |
|---|---|---|---|---|
| Images | 12 | 5 | 2.3GB | 1.1GB (47%) |
| Containers | 8 | 3 | 150MB | 90MB (60%) |
| Volumes | 4 | 2 | 500MB | 200MB (40%) |
Follow up with docker system prune -a when you need to clean house. The -a flag also removes unused images, not just dangling ones.
4. docker inspect - The Truth Is in the JSON
Every Docker object has a complete JSON manifest. inspect reveals it. Use Go templates to extract exactly what you need:
docker inspect -f '{{.NetworkSettings.IPAddress}}' my-container
docker inspect -f '{{range .Mounts}}{{.Source}} -> {{.Destination}}{{println}}{{end}}' my-container
docker inspect -f '{{.State.StartedAt}}' my-container
5. docker stats - Real-Time Resource Monitor
Like top but for containers. Shows CPU, memory, network, and disk I/O - live:
docker stats --no-stream # snapshot
docker stats --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}"
If a container is using 2GB of RAM but your app only needs 200MB, you'll spot it here.
6. docker history - What's Actually In That Image?
Before pulling a 1.5GB image from Docker Hub, check what's inside:
docker history node:20-alpine
| IMAGE | CREATED | SIZE | COMMENT |
|---|---|---|---|
| abc123 | 2 days ago | 5.6MB | /bin/sh -c apk add --no-cache ... |
| def456 | 2 days ago | 112MB | /bin/sh -c mkdir /app |
This shows every layer and its size. You'll often find 500MB of build dependencies that should've been cleaned up in the Dockerfile.
7. docker cp - Move Files In and Out
No need to mount volumes for one-off file transfers:
docker cp ./config.json my-container:/app/config.json # host โ container
docker cp my-container:/var/log/app.log ./app.log # container โ host
8. docker commit - Snapshot a Running Container
Made changes inside a container and want to save them as an image? Don't rebuild - snapshot it:
docker commit my-container my-debug-image:v1
Useful for debugging, but don't build production images this way. It captures everything including temp files and secrets.
9. docker network - See Who's Talking to Whom
docker network ls # list all networks
docker network inspect bridge # see connected containers
docker network create --driver bridge my-net # custom network
Containers on the same custom network can resolve each other by name. No more hardcoding IPs.
10. docker events - Watch Everything Happen
Real-time stream of every Docker event - container starts, stops, health checks, image pulls:
docker events --since 5m
docker events --filter 'event=die' --filter 'container=my-app'
Pipe this into your monitoring stack. When a container unexpectedly dies at 3 AM, you'll know exactly when.
Bottom Line
You don't need to memorize all 10. Start with inspect and system df - you'll use them weekly. Add logs --since for production debugging and events for monitoring. The rest will become muscle memory over time. The gap between "I use Docker" and "I understand Docker" is exactly these 10 commands.
Comments
No comments yet. Start the discussion.