Skip to Content
Mengty Learns
Containers

Docker Cheatsheet

Everyday Docker CLI commands for images, containers, logs, volumes, networks, and cleanup.

referencebeginnerTested with docker 29.4.3Updated Nov 26, 2026

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 image

Containers 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 container
Tip:

Use --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 networks
Gotcha:

docker 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