developer reference

Docker cheat sheet

A practical Docker reference with search, one-click copy and printable PDF output.

Go to commands
35
commands
6
categories
0
dependencies

35 commands visible

Images

8 commands
docker pull <image>[:tag]

Downloads an image from a registry

Imagessafe
Practical example
docker pull nginx:latest
docker pull node:20-alpine
docker build -t <name:tag> .

Builds an image from the Dockerfile in the current directory

Imagessafe
Practical example
docker build -t myapp:1.0 .
# without cache
docker build --no-cache -t myapp:1.0 .
docker images

Lists local images

Imagessafe
Practical example
docker images
docker images -a  # include intermediate images
docker tag <src> <dst>

Creates another tag/reference for an existing image

Imagessafe
Practical example
docker tag myapp:1.0 myuser/myapp:latest
docker push <image>

Pushes an image to a registry

Imagessafe
Practical example
docker push myuser/myapp:latest
docker rmi <image>

Removes a local image

Imagescaution

Removes a local image reference. --force can remove tags used by containers.

Practical example
docker rmi myapp:1.0
docker rmi $(docker images -q)  # all images
docker save -o <file.tar> <image>

Exports an image to a tar file

Imagessafe
Practical example
docker save -o myapp.tar myapp:1.0

Containers

10 commands
docker exec -it <name> <cmd>

Runs a command inside a running container

Containerssafe
Practical example
docker exec -it web bash
docker exec web ls /app
docker logs <name>

Shows container logs

Containerssafe
Practical example
docker logs web
docker logs -f web  # follow logs
docker logs --tail 100 web
docker stop <name>

Stops a container cleanly

Containerssafe
Practical example
docker stop web
docker stop $(docker ps -q)  # all containers
docker rm <name>

Removes a stopped container

Containerscaution

Deletes the container and its writable layer. --force also terminates a running container.

Practical example
docker rm web
docker rm $(docker ps -aq)  # all containers
docker inspect <name>

JSON with all container details

Containerssafe
Practical example
docker inspect web
docker inspect -f '{{.NetworkSettings.IPAddress}}' web
docker cp <src> <name>:<dst>

Copies files between host and container

Containerssafe
Practical example
docker cp ./config.json web:/app/config.json
docker cp web:/app/logs ./logs
docker stats

Real-time CPU/RAM monitor

Containerssafe
Practical example
docker stats
docker stats web --no-stream

Volumes

4 commands
docker volume rm <name>

Removes a volume

Volumescaution

Deletes the volume and its persisted data. Verify backups first.

Practical example
docker volume rm mydata
docker volume prune  # remove all unused images

Networks

4 commands
docker network ls

Lists Docker networks

Networksafe
Practical example
docker network ls
docker network create <name>

Creates a custom bridge network

Networksafe
Practical example
docker network create mynet
docker network create --driver overlay myswarm
docker network connect <net> <container>

Connects a container to a network

Networksafe
Practical example
docker network connect mynet web
docker network inspect <name>

Network details and connected containers

Networksafe
Practical example
docker network inspect mynet

Compose

6 commands
docker compose down

Stops and removes containers and networks

Composecaution

The -v variant deletes declared named volumes and attached anonymous volumes, including their data. External volumes remain.

Practical example
docker compose down
docker compose down -v  # also DELETE volumes and their data
docker compose logs -f

Shows logs for all services

Composesafe
Practical example
docker compose logs -f
docker compose logs -f web  # web service only
docker compose exec <svc> <cmd>

Runs a command in a Compose service

Composesafe
Practical example
docker compose exec web sh
docker compose exec db psql -U postgres
docker compose ps

Status of Compose services

Composesafe
Practical example
docker compose ps
docker compose pull

Updates service images

Composesafe
Practical example
docker compose pull
docker compose pull web

System

3 commands
docker system prune -a

Removes stopped containers, unused networks, unused images and build cache; volumes require --volumes

Systemcaution

Deletes stopped containers, unused networks, unused images and build cache. --volumes also deletes unused anonymous volumes. There is no dry-run option.

Practical example
# inspect disk usage; not a dry run
docker system df
docker system prune -a --volumes  # include anonymous volumes
docker system df

Space used by images, containers and volumes

Systemsafe
Practical example
docker system df
docker system df -v  # detailed usage
docker info

Docker daemon info: version and resources

Systemsafe
Practical example
docker info

How to use this Docker cheat sheet

Does docker compose down delete my data?

By default it removes service containers and networks, not volumes. The -v option removes declared named and attached anonymous volumes and their data; external volumes are not removed.

Can I print this sheet as a PDF?

Use Print PDF. The printable version includes all commands and practical examples, including sections hidden by a search.

Can I use it locally?

Yes. Serve the static files with a local HTTP server. Search, filters and copying run in your browser; the Regex tester requires a worker-enabled HTTP context.