DevOps & ContainersUpdated: 2026-11-06

The Complete Docker CLI, Compose & Container Reference Card

Quick copy-paste syntax for container lifecycles, debugging running pods, pruning dangling volumes, and multi-stage builds.

Docker has revolutionized software delivery by containerizing applications and their dependencies into immutable runtime images. Whether you are troubleshooting crashed microservice containers, reclaiming lost disk space from dangling images, or binding ports on Linux hosts, this cheat sheet provides production-tested commands.

Container Lifecycle Commands

Creating, executing, and managing containerized applications.

TaskCommand SyntaxPurpose
Run in Background`docker run -d -p 8080:80 --name web nginx`Starts container detached, forwarding host port 8080 to container port 80.
Interactive Shell`docker exec -it web /bin/sh`Opens interactive terminal session inside a running container.
Follow Logs`docker logs -f --tail 100 web`Streams last 100 log lines and continues watching live output.
Restart Policy`docker run -d --restart unless-stopped app`Ensures container restarts automatically after host reboot or crash.

Disk Cleanup & Pruning

Reclaiming gigabytes of disk space from stale layers and dangling volumes.

Cleanup OperationCommand SyntaxWhat It Removes
System Prune (All)`docker system prune -af --volumes`Removes all stopped containers, unused networks, unreferenced images, and build cache.
Dangling Images Only`docker image prune`Removes untagged `<none>:<none>` intermediate build layers.
Orphaned Volumes`docker volume prune`Deletes persistent volumes not mounted by any existing container.

Frequently Asked Questions

What is the difference between docker stop and docker kill?

docker stop sends SIGTERM and waits a grace period (10 seconds) for graceful process exit before sending SIGKILL. docker kill sends SIGKILL immediately.

Why do Docker images accumulate so much disk space?

Docker caches every instruction layer from Dockerfile builds. Over months of CI/CD builds, dangling intermediate layers consume tens of gigabytes unless pruned.