Docker & Containers
Docker CLI Cheat Sheet
The Docker commands you use every day — containers, images, volumes, networks, Compose, troubleshooting and cleanup — on one printable page.
Updated November 1, 2026 · Applies to Docker Engine 24+ · Docker Compose v2
Containers
docker run -d --name web -p 8080:80 nginx # run in backgrounddocker ps # running containersdocker ps -a # all, with exit codesdocker logs -f --tail 100 web # follow logsdocker exec -it web sh # shell insidedocker stop web && docker rm web # stop and removedocker restart webImages
docker images # list imagesdocker pull nginx:1.27 # download an imagedocker build -t myapp:1.0 . # build from Dockerfiledocker buildx build --platform linux/amd64 -t myapp:1.0 .docker tag myapp:1.0 user/myapp # tag for a registrydocker push user/myapp # uploaddocker rmi myapp:1.0 # remove imageVolumes & networks
docker volume ls # list volumesdocker volume create data # create a volumedocker run -v data:/var/lib/data appdocker network ls # list networksdocker network create backend # create a networkdocker run --network backend appdocker network inspect backend # who is connectedCompose
docker compose up -d # start the stackdocker compose ps # stack statusdocker compose logs -f api # follow one servicedocker compose up -d --build api # rebuild one servicedocker compose exec api sh # shell in a servicedocker compose config # final config, with .envdocker compose down # stop and removedocker compose down -v # ...and its volumes (data!)Why did it stop?
docker inspect -f '{{.State.ExitCode}} OOMKilled={{.State.OOMKilled}}' webdocker logs --tail 50 web # last output before exitdocker events --since 1h --filter container=webdocker inspect -f '{{.RestartCount}}' web| Exit code | Meaning |
|---|---|
0 |
Finished normally |
1, 2… |
The app’s own error — read the logs |
137 |
SIGKILL: out of memory, or docker stop timeout |
139 |
Segmentation fault |
143 |
SIGTERM, without a handler in the app |
Guide: Exited with code 137
Inspect & debug
docker inspect web # full JSON detailsdocker stats --no-stream # CPU / memory vs. limitdocker top web # processes in containerdocker port web # published portsdocker cp web:/etc/nginx/nginx.conf .docker run --rm -it --entrypoint sh myapp:1.0 # skip the appCleanup
docker system df # what uses disk spacedocker container prune # stopped containersdocker image prune -a # unused imagesdocker builder prune # build cachedocker system prune # stopped containers, unused networks, # dangling images, build cacheWarning
docker system prune --volumes and docker compose down -v also delete volumes — and the data in them.