After running Docker in production for 3 years across dozens of services, these are the 15 commands I actually type every day. Not the reference manual — the practical, muscle-memory commands that solve real problems.
1. docker compose up -d --build
Rebuilds images and starts everything in detached mode. The -d is critical — without it, your terminal is locked. The --build ensures you're running the latest code, not a stale cached layer.
docker compose up -d --build
2. docker compose logs -f --tail=50 <service>
Follow logs for a specific service, showing only the last 50 lines. This is infinitely better than docker logs because it respects your docker-compose.yml service names.
docker compose logs -f --tail=50 api
3. docker exec -it <container> sh
Get a shell inside a running container. Use sh not bash — Alpine images don't have bash. This is how you debug "it works on my machine" issues from inside the actual environment.
docker exec -it my-app-api sh
4. docker system prune -a --volumes
Nuclear cleanup. Removes ALL unused images, containers, networks, AND volumes. I run this monthly when my SSD fills up. ⚠️ This deletes data in unused volumes — don't run it if you have databases you care about.
docker system prune -a --volumes
5. docker compose restart <service>
Restart a single service without rebuilding. Faster than up when you just need to reload config or clear a stuck process.
docker compose restart nginx
6. docker stats
Live CPU/memory/network usage for all running containers. Like htop but for Docker. Leave it running in a split pane while you load-test.
docker stats
7. docker compose up -d --scale <service>=3
Horizontal scaling in one command. Spin up 3 replicas of your API behind the compose load balancer. Great for quick load testing.
docker compose up -d --scale api=3
8. docker image ls --format "table {{.Repository}} {{.Tag}} {{.Size}}"
Clean, readable image list without the noise. I alias this to docker imgs in my .bashrc.
docker image ls --format "table {{.Repository}} {{.Tag}} {{.Size}}"
9. docker run --rm -it -v $(pwd):/work alpine sh
Throwaway container with your current directory mounted. Perfect for testing scripts in a clean environment without polluting your host.
docker run --rm -it -v $(pwd):/work alpine sh
10. docker compose exec db psql -U postgres
Run database commands directly. No need to install psql on your host — use the one inside the container.
docker compose exec db psql -U postgres -c "SELECT count(*) FROM users;"
11. docker build -t myapp:dev --target development .
Multi-stage build targeting a specific stage. Build only the development image without compiling the production layers.
docker build -t myapp:dev --target development .
12. docker network ls && docker network inspect <network>
Debug container networking issues. See which containers are on which network and their IP addresses.
docker network inspect myapp_default
13. docker compose config
Validate and render your docker-compose.yml with all variable substitutions applied. Catches YAML errors and missing .env values before you deploy.
docker compose config > /dev/null && echo "✓ Valid" || echo "✗ Invalid"
14. docker cp <container>:/path/to/file ./local-file
Copy files out of a running container. Essential for extracting logs, config files, or databases backups.
docker cp my-app-api:/app/logs/error.log ./error.log
15. docker compose pull && docker compose up -d
Pull the latest images and restart. This is how you deploy updates in a compose setup — pull new images, recreate containers.
docker compose pull && docker compose up -d
The One-Liner I Use Most
If I could only keep one Docker command, it would be this alias:
alias dup='docker compose up -d --build && docker compose logs -f --tail=20'
Build, start, and follow logs in one keystroke.
Going Deeper
If you're prepping for interviews or want a structured reference, I put together a Docker & Kubernetes Interview Guide with 150+ questions covering real production scenarios — networking, volumes, multi-stage builds, Kubernetes pods/services, Helm, and more.
I also maintain 70+ free online developer tools — no signup required, all client-side.
What's your most-used Docker command? Drop it in the comments — I'm always looking to optimize my workflow.
Top comments (0)