docker
Docker Engine 24.0+Quick reference for everyday Docker CLI commands: container lifecycle, image builds, logs / exec, networking, volumes, Compose, registry and housekeeping — with common options and practical examples.
46 commands
Container Lifecycle
docker run <image>Create and start a new container from an image.
-d detached; -it interactive TTY; --name assign name; -p host:container publish port; -v mount volume; -e KEY=VAL env; --rm auto-remove on exit; --restart=always|unless-stopped|on-failure
docker run -d --name web -p 8080:80 -v $PWD:/usr/share/nginx/html:ro nginx:alpinedocker start|stop|restart <container>Start, stop or restart an existing container (by name or id).
-t N seconds to wait before kill (default 10)
docker restart web && docker logs --tail 50 webdocker rm <container>Remove one or more stopped containers.
-f force-remove running; -v also remove anonymous volumes
docker rm -f $(docker ps -aq)docker psList containers (default: only running).
-a all; -q quiet (ids only); -s with size; --format go-template; --filter status|name=...
docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'docker rename <c> <new>Rename a container.
docker rename web-1 gateway-webdocker update <c>Update a container's resource limits or restart policy at runtime.
--cpus N; --memory SIZE; --memory-swap SIZE; --restart policy
docker update --cpus 1.5 --memory 1g apidocker wait <c>Block until the container stops, then print its exit code.
docker wait db && echo "db stopped"docker top <c>Show running processes inside a container (ps of the host PID namespace).
docker top webLogs & Exec
docker logs <c>Fetch logs of a container.
-f follow; --tail N; --since timestamp|duration; -t with timestamps; --details
docker logs -f --tail 200 -t api | grep ERRORdocker exec -it <c> <cmd>Run a command inside a running container (commonly an interactive shell).
-i keep STDIN open; -t allocate a pseudo-TTY; -u user; -w workdir; -e KEY=VAL
docker exec -it -u postgres db psql -U postgres app_productiondocker attach <c>Attach local STDIN/STDOUT to a running container (same as `docker start -i`).
--sig-proxy proxy signals; --no-stdin
docker attach web && Ctrl-p Ctrl-q to detachdocker cp <c>:<src> <dest>Copy files/folders between a container and the local filesystem.
-L follow symlink; -a archive mode
docker cp db:/var/lib/postgresql/data ./pgdataInspection
docker inspect <obj>Return low-level info on Docker objects (container, image, volume, network).
-f go-template; --type container|image|network|volume; -s size
docker inspect -f '{{.NetworkSettings.IPAddress}}' webdocker statsLive stream of CPU / memory / network / disk usage for running containers.
--no-stream one shot; -a all (incl stopped); --format; --no-trunc
docker stats --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}'docker diff <c>Inspect changes (added / changed / deleted) on a container's filesystem.
docker diff web | head -20Image Operations
docker pull <image>[:tag]Pull an image (or repository) from a registry.
-a all tagged images; --platform linux/amd64; -q quiet; --disable-content-trust
docker pull --platform linux/amd64 nginx:1.27-alpinedocker imagesList images on the local daemon.
-a all (incl intermediate); -q ids only; --digests; --filter dangling=true
docker images --format '{{.Repository}}:{{.Tag}}\t{{.Size}}' | sort -k2 -h | tail -20docker build <path>Build an image from a Dockerfile.
-t name:tag; -f Dockerfile path; --no-cache; --build-arg KEY=VAL; --target stage; --progress=plain; --platform
docker build -t myapp:dev --build-arg NODE_ENV=development --progress=plain .docker tag <src> <dest>Create a tag that points to an existing image (alias / push target).
docker tag myapp:dev registry.example.com/team/myapp:1.2.0docker push <image>Upload an image (or repository) to a registry.
--disable-content-trust; -a all tagged variants; --quiet
docker push registry.example.com/team/myapp:1.2.0docker rmi <image>Remove one or more images.
-f force (untag also when children); --no-prune keep untagged parents
docker rmi -f $(docker images --filter 'dangling=true' -q)docker image prune / docker save / docker loadReclaim space (filter dangling/older than Xh); save/load image to/from tar.
-a all; --filter 'until=24h'; -o file.tar; -i file.tar
docker image prune -af --filter 'until=72h' && docker save -o nginx.tar nginx:alpinedocker history <image>Show the layers / intermediate history of an image.
--no-trunc; --human; -q ids
docker history --no-trunc --human myapp:devNetwork
docker network lsList networks.
--filter driver=bridge|overlay; -q ids; --format
docker network ls --filter driver=bridge --format '{{.Name}}'docker network create <name>Create a user-defined bridge network for service discovery & DNS.
--driver bridge|overlay|macvlan; --subnet CIDR; --gateway; --ipv6; --internal
docker network create --driver bridge --subnet 10.20.0.0/24 mynetdocker network connect|disconnect <net> <c>Attach / detach a running container to a network.
--ip IPV4; --ip6 IPV6; --alias hostname alias; --link container
docker network connect mynet webdocker network rm / docker network pruneRemove one or more networks / clean up unused.
-f force; --filter 'until=24h'
docker network prune -fVolume & Storage
docker volume lsList volumes.
--filter dangling=true|driver|name; -q ids; --format
docker volume ls --filter dangling=true -qdocker volume create <name>Create a named volume (managed by Docker, out of container's UFS).
--driver local; --opt type=nfs; --opt o=addr; --opt device=:/path
docker volume create --driver local --opt type=nfs --opt o=addr=10.0.0.1 --opt device=:/exports/data pgdatadocker volume rm / docker volume pruneRemove one or more volumes / clean up unused.
-f force; --filter 'label=...'
docker volume rm $(docker volume ls -q --filter dangling=true)docker volume inspect <vol>Show low-level details of a volume (mountpoint, driver, options).
docker volume inspect pgdata --format '{{.Mountpoint}}'Docker Compose
docker compose upBuild (if needed), create and start services from compose.yaml.
-d detached; --build force build; --force-recreate; --pull always|missing|never; -f file
docker compose -f compose.prod.yaml up -d --pull alwaysdocker compose downStop and remove containers, networks; default also removes anonymous volumes.
--volumes named vols too; --rmi all|local; --remove-orphans; -t N timeout
docker compose down --rmi local --remove-orphansdocker compose ps / logsList Compose services / view logs.
ps -q ids only; logs -f follow; --tail N; --since
docker compose ps --format json | jq '.[] | {Name, State}' && docker compose logs -f --tail 100 apidocker compose exec / runRun a command in a running / new service container.
exec --user; exec -e VAR=val; run --rm removes container after
docker compose exec db psql -U postgres app && docker compose run --rm api npm run migratedocker compose build / pull / pushBuild images / pull images from registry / push images to registry for a Compose project.
--no-cache; --pull; --quiet; --parallel
docker compose build --no-cache api workerdocker compose restart / stop / start / scaleLifecycle shortcuts for services; scale adjusts the number of replicas.
restart <svc>; stop <svc>; start <svc>; scale api=4 worker=2
docker compose restart api && docker compose up -d --scale worker=4Registry & Hub
docker login [server]Authenticate to a registry. Use `docker login` for Docker Hub.
-u user; -p password; --password-stdin
echo "$REGISTRY_TOKEN" | docker login ghcr.io -u myuser --password-stdindocker logout [server]Remove credentials for a registry from config.
docker logout && docker info 2>/dev/null | headdocker search <term>Search Docker Hub for images.
--filter stars=N; --limit N; --format
docker search --filter stars=100 --limit 5 postgresSystem & Cleanup
docker system dfShow docker disk usage (images, containers, volumes, build cache).
-v verbose
docker system df -v | sort -k7 -h | taildocker system pruneRemove all stopped containers, dangling images, unused networks.
-a all images; --volumes also volumes; --filter 'until=24h'; -f force
docker system prune -af --volumes --filter 'until=72h'docker builder pruneClean the build cache (free disk space from old layers).
-af; --filter 'until=72h'; --keep-storage SIZE
docker builder prune -af --filter 'until=72h'docker context ls / useManage Docker contexts — for multi-host / multi-daemon (incl remote contexts over SSH).
ls --format json; use myctx
docker context create myhost --docker host=ssh://user@server && docker context use myhost && docker psdocker infoDisplay system-wide information; useful when debugging.
--format
docker info -f '{{.DriverStatus}}'docker port <c>List port mappings (host ↔ container) for a container.
docker port web 80Related command cheatsheets
aws cli
Quick reference for the AWS Command Line Interface: configure credentials, IAM identity, EC2 / Lambda / S3 / DynamoDB / IAM, profiles, SSO, and pagination / output formatting — with common options and practical examples.
40 commands
AWS CLI v2
azure cli
Quick reference for the Azure CLI (az): authentication, subscription / resource management, VM / AKS / Storage / App Service / Key Vault, query formatting, and CI-friendly workflows — with common options and practical examples.
43 commands
Azure CLI 2.60+
gcloud
Quick reference for gcloud (Google Cloud CLI), gsutil, and bq commands: authentication, project / IAM, Compute / GKE / BigQuery / Cloud Storage, config, and Cloud Build / Deploy — with common options and practical examples.
48 commands
gcloud 480+
kubectl
Quick reference for kubectl, the Kubernetes command-line client: contexts, get/describe, apply, logs/exec, rollout, scaling and debugging — with common options and practical examples.
40 commands
kubectl 1.28+
Trademark & Use Notice
These command-line tool cheatsheets are open community references. The names, logos, and trademarks of the tools referenced here (such as Git™, Docker™, Kubernetes®, kubectl, PostgreSQL®, MySQL®, Redis™, MongoDB®, Linux™, PowerShell™, Vim™, and others) are the property of their respective owners and are used here solely for identification and reference purposes.
All content in these cheatsheets is independently authored as a simplified, self-contained reference. It is not affiliated with, endorsed by, or sourced from any official documentation. Command listings, flag descriptions, and examples are original simplifications; for authoritative information please consult the official documentation of each tool.
Command syntax and option flags may differ across tool versions. The version tags shown reflect stable releases; behavior may differ in other versions. This cheatsheet does not imply any preference or recommendation by the trademark holders.
If a trademark or copyright owner believes that any content on this site infringes their rights, please send an email to [email protected]. Upon receiving valid proof of rights, we will modify or remove the relevant content within a reasonable period.
This website assumes no legal liability for any direct or indirect losses arising from the use of information presented on these pages.
About Docker
Docker is an open-source container engine originally released by Solomon Hykes at PyCon 2013 and now stewarded by Docker Inc. and the Cloud Native Computing Foundation; the current stable line is Docker Engine 24.0+ (the runtime component), with `dockerd` orchestrating containers built from OCI-compliant images. Containers package an application together with its dependencies (libraries, configuration, runtime) into an image layered on a read-only base; layers are content-addressed by SHA-256, cached across builds, and shared between running containers. Docker's CLI covers the full lifecycle — `docker build`, `docker run`, `docker ps`, `docker exec`, `docker logs`, `docker compose` for multi-container apps, `docker network` and `docker volume` for plumbing, `docker push` / `docker pull` for registries — and is the lingua franca of container operations even on Kubernetes clusters. Use Docker locally to mirror production, in CI to run reproducible jobs, and as the substrate for Compose stacks; reach for Kubernetes when you need automated scheduling, self-healing, or rolling deploys across many nodes. Docker daemon binds to a local socket by default — secure it with TLS, and never expose it to the public internet.
Cheatsheet version 1.0.0