Skip to content
ohsudo
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

Terminal window
docker run -d --name web -p 8080:80 nginx # run in background
docker ps # running containers
docker ps -a # all, with exit codes
docker logs -f --tail 100 web # follow logs
docker exec -it web sh # shell inside
docker stop web && docker rm web # stop and remove
docker restart web

Images

Terminal window
docker images # list images
docker pull nginx:1.27 # download an image
docker build -t myapp:1.0 . # build from Dockerfile
docker buildx build --platform linux/amd64 -t myapp:1.0 .
docker tag myapp:1.0 user/myapp # tag for a registry
docker push user/myapp # upload
docker rmi myapp:1.0 # remove image

Volumes & networks

Terminal window
docker volume ls # list volumes
docker volume create data # create a volume
docker run -v data:/var/lib/data app
docker network ls # list networks
docker network create backend # create a network
docker run --network backend app
docker network inspect backend # who is connected

Compose

Terminal window
docker compose up -d # start the stack
docker compose ps # stack status
docker compose logs -f api # follow one service
docker compose up -d --build api # rebuild one service
docker compose exec api sh # shell in a service
docker compose config # final config, with .env
docker compose down # stop and remove
docker compose down -v # ...and its volumes (data!)

Why did it stop?

Terminal window
docker inspect -f '{{.State.ExitCode}} OOMKilled={{.State.OOMKilled}}' web
docker logs --tail 50 web # last output before exit
docker events --since 1h --filter container=web
docker 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

Terminal window
docker inspect web # full JSON details
docker stats --no-stream # CPU / memory vs. limit
docker top web # processes in container
docker port web # published ports
docker cp web:/etc/nginx/nginx.conf .
docker run --rm -it --entrypoint sh myapp:1.0 # skip the app

Cleanup

Terminal window
docker system df # what uses disk space
docker container prune # stopped containers
docker image prune -a # unused images
docker builder prune # build cache
docker system prune # stopped containers, unused networks,
# dangling images, build cache

Warning

docker system prune --volumes and docker compose down -v also delete volumes — and the data in them.