Show Menu
Cheatography
  • Building New PDFs

Docker 29 and Docker Compose v5 Commands Cheat Sheet by

Everyday Docker Engine 29 and Docker Compose v5 commands: containers, images, builds, volumes, networks, cleanup and system info, plus the pitfalls hit while testing them. Checked on Docker Engine 29.9, Compose v5.6 and Buildx v0.38.

Containers

docker run -d --name web -p 8080:80 nginx:1.30
Run in the background and map host port 8080 to container port 80
docker run -it --rm ubuntu­:26.04 bash
Intera­ctive shell; container is removed when it exits
docker ps
List running containers
docker ps -a
List all contai­ners, including stopped ones
docker stop web / docker start web
Stop / start a container
docker restart web
Restart a container
docker rm web
Remove a stopped container
docker rm -f web
Force-­remove a running container
docker logs -f web
Follow a contai­ner's logs
docker logs --tail 100 web
Show only the last 100 log lines
docker exec -it web sh
Open a shell inside a running container
docker cp web:/p­ath­/file .
Copy a file from the container to the host
docker inspect web
Full container details as JSON
docker stats
Live CPU / memory / network usage
docker top web
Processes running inside the container
docker port web
Show port mappings
docker update --restart unless­-st­opped web
Change the restart policy of an existing container
docker run --init ...
Small init as PID 1, so stop signals are forwarded (no 10 s wait on docker stop)
Names like web are examples; any container name or ID works.

Images

docker images
List local images
docker images --tree
Show the platforms inside multi-­pla­tform images
docker pull nginx:1.30
Pull an image
docker tag myapp user/m­yap­p:1.0
Add a new name or tag
docker push user/m­yap­p:1.0
Push to a registry
docker rmi nginx:1.30
Remove an image
docker history nginx:1.30
Show image layers
docker buildx imagetools inspect nginx:­1.3­0-a­lpine
Platforms of a remote image, without pulling it
docker save -o img.tar myapp
Export an image to a file
docker load -i img.tar
Load an image from a file
docker login / docker logout
Log in to / out of a registry
 

Builds

docker build -t myapp .
Build with the Dockerfile in the current directory
docker build -f Docker­fil­e.prod -t myapp .
Use a different Dockerfile
docker build --no-cache -t myapp .
Build without the cache
docker build --pull -t myapp .
Pull the base image again
docker build --target dev -t myapp:dev .
Build only up to one stage of a multi-­stage file
docker build --buil­d-arg VERSIO­N=1.2 .
Pass a build argument (never for passwords: it stays in the image history)
docker build --secret id=tok­en,­env­=TOKEN .
Pass a secret without leaving it in the image
docker build --progress plain .
Show the full build output
docker buildx build --platform linux/­amd­64,­lin­ux/­arm64 -t user/app --push .
Build for two platforms and push

Volumes

docker volume create data
Create a named volume
docker volume ls
List volumes
docker volume inspect data
Volume details (mount point on the host)
docker volume rm data
Remove a volume
docker run -v data:/­app­/data myapp
Mount a named volume
docker run -v "­$(p­wd)­:/a­pp" myapp
Bind-mount the current directory

Networks

docker network create appnet
Create a user-d­efined network (conta­iners reach each other by name)
docker network ls
List networks
docker network inspect appnet
Show the containers on a network
docker run --network appnet --name db postgr­es:18
Start a container on a network
docker network connect appnet web
Attach a running container to a network
docker network rm appnet
Remove a network

Common run options

-d
Run in the background
-it
Intera­ctive mode + terminal
-p host:c­ont­ainer
Port mapping
-v source­:co­nta­ine­r-path
Mount a volume or directory
-e KEY=VALUE
Enviro­nment variable
--name
Container name
--rm
Remove automa­tically when it exits
--network
Network to join
--restart
Restart policy (no, on-fai­lure, always, unless­-st­opped)
 

Docker Compose (v5)

docker compose up -d
Start all services in the background
docker compose up -d --build
Rebuild images, then start
docker compose up -d --wait
Return only when all services are healthy
docker compose up -d app
Recreate / rebuild only one service
docker compose down
Stop and remove containers and networks
docker compose down -v
... and the volumes too (deletes data)
docker compose ps
Service status
docker compose logs -f app
Follow one service's logs
docker compose exec app sh
Shell in a running service container
docker compose run --rm app npm test
Run a one-off command
docker compose pull
Pull the latest images
docker compose restart app
Restart a service (does NOT apply a changed compose file: use up -d)
docker compose watch
Sync or rebuild when files change (devel­opment)
docker compose --profile tools up -d
Also start services in a profile
docker compose config
Print the final merged config­uration

Cleanup and disk usage

docker system df
Disk usage by images, contai­ners, volumes, cache
docker container prune
Remove stopped containers
docker image prune -a
Remove all unused images
docker builder prune
Clear the build cache
docker builder prune --filter until=168h
Clear only cache unused for 7+ days
docker volume prune
Remove unused anonymous volumes
docker volume prune -a
Remove ALL unused volumes, including named database volumes
docker system prune
General cleanup (volumes not included)
docker system prune --volumes
Also anonymous volumes (named ones are kept since Docker 23)

System inform­ation

docker version
Client and server versions
docker info
Engine config­uration and storage details
docker events
Live event stream
docker context ls
Docker endpoints you can switch between

Pitfalls found while testing

docker stop takes 10 seconds
The program is PID 1 and ignores SIGTERM: handle it, or run with --init
postgr­es:18 exits right after start
Version 18 mounts /var/l­ib/­pos­tgr­esql, not /var/l­ib/­pos­tgr­esq­l/data
Database healthy before it is ready
Add -h 127.0.0.1 to pg_isready / mysqladmin ping
Redis health­check passes with a wrong password
redis-cli ping exits 0 on auth errors; add | grep -q PONG
Changing MYSQL_­ROO­T_P­ASSWORD has no effect
Used only on the first initia­lis­ation of the data volume
Edited a bind-m­ounted file, container sees the old one
Editors replace the file; mount the directory instead, or restart
--env-file values include quotes
docker run --env-file keeps quotes; Compose env_file strips them
Secret deleted with rm is still in the image
Every layer keeps it; ARG and ENV are visible too: use --secret
exec format error
CPU archit­ecture mismatch: use --platform or build multi-­pla­tform
Container named web resolves to 127.0.0.53
.web is a real top-level domain; pick another name

Source and longer explan­ations

Every command above was run on Docker Engine 29.9, Docker Compose v5.6 and Buildx v0.38 while writing a free Docker tutorial. Each one is explained there with its real output: https:­//c­odi­ngk­it.c­om­/do­cke­r/c­hea­tsheet/
               
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Docker OSX use Cheat Sheet
          DevOps Troubleshooting Study Guide Cheat Sheet
          DevOps Cheat Sheet