CHEATSHEET • DOCKER & COMPOSE

Docker & Docker Compose Cheatsheet

Fast-copy container runtime, image build, network/volume debugging, disk cleanup, and multi-container Compose commands.

01Container Lifecycle & Runtime Debugging

List all running and stopped containers with ports and status
docker ps -a
Run a container in background with port mapping and restart policy
docker run -d --name web --restart unless-stopped -p 8080:80 nginx:alpine
Open an interactive shell inside a running container
docker exec -it <container> /bin/sh
Stream live container stdout/stderr logs (last 100 lines)
docker logs -f --tail 100 <container>
Monitor live CPU, memory, and network I/O across containers
docker stats --no-stream
Extract container IP address or full JSON runtime metadata
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container>

02Image Builds, Registries & Cleanup

Build and tag an image from the current directory Dockerfile
docker build -t my-app:1.0.0 .
Tag a local image and push it to a container registry
docker tag my-app:1.0.0 ghcr.io/org/my-app:1.0.0 && docker push ghcr.io/org/my-app:1.0.0
Inspect image layer sizes to spot bloated build steps
docker history --no-trunc my-app:1.0.0
Check Docker disk usage and prune unused images & build cache
docker system df && docker system prune -af
Advertisement

03Networks, Volumes & File Copy

Create an isolated bridge network for container DNS discovery
docker network create --driver bridge app-net
Create and list named volumes for persistent database state
docker volume create pgdata && docker volume ls
Copy config files or logs between host and container
docker cp <container>:/var/log/app.log ./app.log

04Docker Compose v2 Commands

Rebuild images and start all Compose services in detached mode
docker compose up -d --build
Tail aggregated logs across all services or a single service
docker compose logs -f --tail=50
Run a one-off database migration or shell inside a Compose service
docker compose exec app /bin/sh
Validate syntax and render merged environment variables
docker compose config
Stop and remove containers and networks (add -v to wipe volumes)
docker compose down
Copied to clipboard!