Most developers know docker run and docker-compose up. Here are 9 Docker commands that save hours but nobody teaches you.
1. docker system df — See What's Eating Your Disk
docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 47 3 12.4GB 11.2GB (90%)
Containers 12 1 2.3GB 2.1GB (91%)
Local Volumes 8 2 4.1GB 3.8GB (92%)
Build Cache 0 0 0B 0B
90% of your Docker disk usage is reclaimable. You're wasting gigabytes.
2. docker system prune -a — Reclaim Everything
docker system prune -a --volumes
This removes:
- All stopped containers
- All unused networks
- All unused images (not just dangling)
- All unused volumes
I freed 38GB on my dev machine. Check yours.
3. docker stats — Real-Time Resource Monitor
docker stats --format "table {{.Name}} {{.CPUPerc}} {{.MemUsage}}"
NAME CPU % MEM USAGE / LIMIT
postgres 0.15% 125MiB / 8GiB
redis 0.08% 12MiB / 8GiB
web-app 2.34% 456MiB / 8GiB
Better than htop for finding container memory leaks.
4. docker exec with Environment Variables
docker exec -e DEBUG=true -e LOG_LEVEL=verbose my-container python3 debug.py
Inject env vars into a running container without restarting. Perfect for debugging production issues.
5. docker cp — Copy Files In/Out of Containers
# Copy logs out of a container
docker cp my-container:/var/log/app.log ./app.log
# Copy config into a container
docker cp ./config.yml my-container:/etc/app/config.yml
No volume mount needed. Works on running or stopped containers.
6. docker diff — See What Changed Inside a Container
docker diff my-container
C /var/log
A /var/log/app.log
C /tmp
A /tmp/cache.db
D /etc/old-config.yml
A = added, C = changed, D = deleted. Instant forensics.
7. docker history — Understand Image Layers
docker history --no-trunc --format "{{.Size}} {{.CreatedBy}}" my-image | head -10
Find which Dockerfile instruction made your image 2GB. Usually it's COPY . . including node_modules.
8. docker compose up --build --force-recreate
docker compose up --build --force-recreate --remove-orphans -d
The nuclear option: rebuilds images, recreates containers, removes orphans. Use when "works on my machine" meets "doesn't work in Docker."
9. docker logs with Timestamps and Follow
docker logs --since 5m --follow --timestamps my-container 2>&1 | grep ERROR
Tail logs from the last 5 minutes, with timestamps, filtered to errors. Better than scrolling through 10,000 lines.
Bonus: One-Liner Health Check
docker ps --format '{{.Names}}: {{.Status}}' | grep -v "healthy"
Instantly find unhealthy containers.
I share practical developer tools and CLI tricks weekly. Follow for more time-saving commands.
Need automated infrastructure monitoring or web scraping? Email me at spinov001@gmail.com
Top comments (0)