Quick reference
Images
docker images
docker pull nginx:1.27
docker build -t api:1.0 .
docker history api:1.0
docker inspect nginx:1.27Containers
docker ps -a
docker run -d -p 8080:80 nginx
docker logs -f --tail 100 api
docker exec -it api sh
docker stats --no-streamCompose
docker compose up -d
docker compose ps
docker compose logs -f api
docker compose config
docker compose down -vCleanup
docker system df
docker container prune
docker image prune -a
docker volume prune -a
docker builder pruneExplained
Images
Start with images. docker images lists what is local, docker pull nginx:1.27 fetches a pinned tag, and docker build -t api:1.0 . builds from the Dockerfile in the current directory. docker history api:1.0 shows the layers, and docker inspect nginx:1.27 prints the JSON behind the tag.
Containers and Compose
docker ps -a shows running and stopped containers, and docker run -d -p 8080:80 nginx starts one in the background with a port mapped. docker logs -f --tail 100 api follows the last hundred lines, docker exec -it api sh opens a shell, and docker stats --no-stream gives one snapshot of CPU and memory. Compose uses the same verbs with a project: docker compose up -d, ps, logs -f api, config and down -v.
Cleanup
Cleanup is where the disk comes back: docker system df shows what is using space, and container prune, image prune -a, volume prune -a and builder prune each target one kind of leftover.
The honest caveat: prune commands delete data. docker volume prune -a removes named volumes that no container is using, and the database inside one will not ask twice.
The lesson: five commands per area, typed from memory, beat a search engine and a guess.
In one line
Five per area beats fifty. You need the five you type weekly, not every flag in the manual.
Check the disk
docker system dfMore notes: Docker & containers
- P1995 Dockerfile mistakes to avoid
- P196Alpine vs Debian base images
- P1949 docker commands for building and shipping images
- P1649 docker compose commands for daily work
- P163Anatomy of a container image reference
- P152Docker Compose vs Kubernetes
- P147Quiz: 3 container questions
- P133Anatomy of a docker run command
Open in the notes app: search, filters, copy This note on GitHub