Docker & Containers Master Cheat Sheet: CLI Commands, Compose & Image Pruning
The complete practical reference for container lifecycle operations, multi-stage Dockerfile architecture, Docker Compose v2 commands, port mappings, and deep storage reclamation.
1. Container Lifecycle Operations
docker run -d \
--name my-web \
--restart unless-stopped \
-p 8080:80 \
-v $(pwd)/html:/usr/share/nginx/html:ro \
nginx:alpineSpawns a restart-resilient container with host port binding and read-only volume mounting.
docker exec -it my-web shDrops into an interactive terminal session inside the running container.
docker logs -f --tail 100 -t my-webStreams the last 100 log lines with precise ISO timestamps.
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}"Outputs a compact diagnostic table of active container resource consumption.
2. Multi-Stage Dockerfile Best Practices
3. Docker Compose v2 Orchestration
docker compose up -d --buildRebuilds updated Dockerfiles and boots all dependent services detached.
docker compose down -v --remove-orphansStops containers, deletes networks, and cleans up persistent storage volumes.
docker compose restart apiRestarts only the target service without disrupting other microservices.
4. Deep Storage Reclamation & Layer Pruning
docker system dfDisplays space used by images, containers, local volumes, and build cache.
docker system prune -af --volumesDeletes all stopped containers, unused networks, unreferenced images, and orphan volumes.
docker builder prune -afFrees gigabytes of cached intermediate layers accumulated during docker build commands.
Related Free Online Tools
Put these techniques into practice immediately with our privacy-first browser utilities: