Docker Cheat Sheet
Build, run, ship, and debug container images — the day-to-day lifecycle every image spends in CI and production.
Images
13docker build -t NAME:TAG .Build an image from the Dockerfile
docker build --no-cache -t NAME .Build bypassing the cache
docker pull IMAGEPull an image from a registry
docker push USER/IMAGE:TAGPush to a registry
docker imagesList local images
docker image inspect IMAGEFull metadata as JSON
docker image prune -aRemove all unused images
docker rmi IMAGETag or remove an image
docker history IMAGELayers a build produced
docker tag IMAGE NEWNAME:TAGRe-tag an image
docker save IMAGE | gzip > image.tar.gzExport an image to a tarball
docker load < image.tar.gzImport images from a tarball
docker build --target BUILDER -t NAME .Build up to a specific stage (multi-stage)
Containers
16docker run IMAGERun a container
docker run --name web -d -p 8080:80 IMAGEDetached, named, port-mapped
docker run --rm IMAGERemove the container on exit
docker run -it IMAGE /bin/shInteractive shell
docker run -v /host:/container IMAGEMount a host directory
docker run --env VAR=value IMAGESet an environment variable
docker run --env-file .env IMAGELoad env from a file
docker run --network host IMAGEUse the host network
docker run --restart unless-stopped IMAGERestart policy
docker psRunning containers
docker ps -aAll containers
docker start/stop/restart CONTAINERControl a container
docker rm CONTAINERRemove a stopped container
docker rm -f CONTAINERForce-remove a running container
docker container pruneRemove all stopped containers
docker rename OLD NEWRename a container
Shell, Logs & Debug
10docker exec -it CONTAINER /bin/shOpen a shell inside a container
docker exec CONTAINER CMDRun one command inside
docker logs CONTAINERSTDOUT/STDERR of the container
docker logs -f --tail 100 CONTAINERFollow the last 100 lines
docker logs CONTAINER 2>&1 | grep errorScan logs for errors
docker top CONTAINERProcesses inside the container
docker diff CONTAINERWhich files the container changed
docker cp CONTAINER:/path/to/file .Copy a file out of a container
docker stat CONTAINERLive CPU/memory/network usage
docker inspect CONTAINER | grep IPAddressRead the container IP
Networks
6docker network lsList networks
docker network create NAMECreate a network
docker network connect NET CONTAINERAttach a running container
docker network disconnect NET CONTAINERDetach a container
docker run --network NET IMAGERun on a custom network
docker port CONTAINERShow published ports
Volumes & Storage
6docker volume lsList named volumes
docker volume create NAMECreate a named volume
docker run -v NAME:/data IMAGEUse a named volume
docker run --mount type=bind,src=/host,dst=/container IMAGEMount with build-args syntax
docker volume pruneRemove unused volumes
docker volume inspect NAMEWhere the volume lives
Cleanup & Housekeeping
5docker system dfDisk usage by images/containers/volumes
docker system pruneRemove dangling images and stopped containers
docker system prune -a --volumesFull cleanup (careful)
docker image prune -fDrop dangling images only
docker eventsStream live engine events
Registry & Auth
5docker loginAuthenticate to a registry
docker logoutClear registry credentials
docker search TERMSearch the registry
docker manifest inspect IMAGEInspect tags and platforms
docker run --platform linux/amd64 IMAGEForce an architecture