Wiki· Updated 19 Oct 2026
Cheat sheet: Docker and Compose
Docker and Docker Compose commands: containers, logs, images, volumes, networks, cleanup.
Containers
docker ps # running
docker ps -a # all, including stopped
docker run -d --name web -p 8080:80 nginx # run in the background
docker run --rm -it ubuntu bash # throwaway, with a terminal
docker stop web && docker start web
docker restart web
docker rm -f web # remove (stops it first)
docker exec -it web sh # get a shell inside
docker exec web cat /etc/nginx/nginx.conf # run a command
docker cp web:/etc/nginx/nginx.conf . # file out of the container
docker cp ./index.html web:/usr/share/nginx/html/
Logs and state
docker logs -f --tail 100 web # last 100 lines and follow
docker logs --since 30m web
docker stats --no-stream # CPU and memory of all containers
docker inspect web # everything about the container
docker inspect -f '{{.State.Health.Status}}' web
docker inspect -f '{{json .Mounts}}' web # where the data is mounted
docker top web # processes inside
docker events --since 10m # what happened
Images
docker images
docker pull nginx:1.27
docker build -t myapp:1.0 .
docker build --no-cache -t myapp:1.0 .
docker tag myapp:1.0 registry.example.com/myapp:1.0
docker push registry.example.com/myapp:1.0
docker rmi myapp:1.0
docker history myapp:1.0 # which layers
Volumes and networks
docker volume ls
docker volume inspect pgdata # Mountpoint — where the data is
docker run --rm -v pgdata:/data -v "$PWD":/backup alpine tar czf /backup/pgdata.tgz -C /data .
docker network ls
docker network inspect bridge
docker network create mynet
docker network connect mynet web
Compose
docker compose up -d # start (and recreate what changed)
docker compose up -d --build # rebuild images
docker compose ps
docker compose logs -f --tail 100 app
docker compose exec app sh
docker compose restart app
docker compose pull && docker compose up -d # update images
docker compose down # remove containers, volumes stay
docker compose down -v # and volumes — data is deleted!
docker compose config # final config with variables filled in
docker compose -f compose.yml -f compose.override.yml up -d
docker compose ls # all projects on the server
Space and cleanup
docker system df # space used by images, volumes, cache
docker image prune # untagged images
docker image prune -a # all unused images
docker builder prune # build cache
docker container prune # stopped containers
docker volume prune # volumes without containers — careful, that is data
Log limit for all containers — /etc/docker/daemon.json, then systemctl restart docker (applies to new containers):
{ "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "5" } }
rs clean does all of this step by step. Turn docker run into compose — the converter.
