Docker & Docker Compose Cheat Sheet
Production Docker CLI reference: container creation, logs tailing, exec sh, compose commands, and disk pruning.
Container Lifecycle (5 commands)
docker run -d -p 8080:80 --name my-app nginx:alpine
Runs an Nginx container in detached (-d) background mode on port 8080.
docker ps
Lists all currently running Docker containers.
docker stop <container-id-or-name>
Gracefully sends SIGTERM followed by SIGKILL to stop container execution.
docker start <container-id-or-name>
Starts an existing, stopped container without recreating its configuration.
docker rm -f <container-id-or-name>
Forcefully removes a container instance from your local disk.
Images & Registry (4 commands)
docker images
Lists all Docker images locally cached on the system.
docker pull node:20-alpine
Downloads a target image from Docker Hub without launching a container.
docker build -t prowebtools/api:v1 .
Builds a Docker image from a Dockerfile in the current directory (.).
docker rmi <image-id-or-name>
Removes an image from local storage.
Debugging & Inspection (4 commands)
docker logs -f --tail 100 <container-name>
Follows (-f) container stdout and stderr logs starting from last 100 lines.
docker exec -it <container-name> sh
Opens an interactive (-it) shell inside a running container.
docker stats
Streams real-time CPU, RAM, network, and disk I/O metrics across containers.
docker inspect <container-name>
Dumps complete low-level JSON configuration including network IP addresses.
Docker Compose (4 commands)
docker compose up -d
Builds, creates, and starts all services declared in docker-compose.yml.
docker compose down -v
Stops and removes containers, default networks, and named volumes (-v).
docker compose ps
Lists all services managed by the current directory's compose file.
docker compose logs -f <service-name>
Follows log streams for a specific service (e.g. web, db, redis).
Disk Cleanup (2 commands)
docker system prune -af --volumes
Comprehensive cleanup: deletes stopped containers, unused networks, and dangling images.
docker image prune -a
Removes all images not currently referenced by at least one container.