Docker Cheatsheet
Everyday Docker CLI commands for images, containers, logs, volumes, networks, and cleanup.
TL;DR
A quick reference for the Docker commands you reach for daily: building images, running and inspecting containers, tailing logs, managing Compose stacks, and reclaiming disk space.
Images and builds
docker build -t myapp:1.0.0 . # build from Dockerfile in current directory
docker build --no-cache -t myapp:ci . # force a clean build without layer cache
docker images # list local images
docker history myapp:1.0.0 # show each layer's command and size
docker rmi myapp:1.0.0 # remove an imageContainers and debugging
docker ps # list running containers
docker ps -a # include stopped containers
docker run --rm -d --name api -p 8080:8080 myapp:1.0.0
docker logs -f --tail 100 api # follow the last 100 log lines
docker exec -it api sh # open an interactive shell in a running container
docker inspect api # dump low-level JSON config and network state
docker rm -f api # force-stop and remove a containerUse --rm on one-off docker run commands so exited containers do not pile up on disk.
Compose and cleanup
docker compose up -d --build # rebuild and start services in the background
docker compose logs -f # stream logs for all services
docker compose down # stop and remove containers and default network
docker system df # check disk usage by images, containers, and cache
docker system prune # remove stopped containers, dangling images, unused networksdocker compose down -v and docker system prune --volumes delete anonymous and named volumes — double-check before running them near a local database you want to keep.
Check yourself
Check Yourself
1. Which command shows the individual layers that make up a Docker image and how much space each adds?
2. What does the --rm flag do on docker run?
Sources
Related Notes
Non-Root Containers & Image Scanning
Harden containers with numeric non-root UIDs, read-only root filesystems, dropped Linux capabilities, minimal base images, and CI vulnerability scanning.
Service Routing: Ingress → Service → Pod
How a Kubernetes request travels from a user's browser through Ingress and Service to a healthy Pod and back.