# devops / docker / cheatsheet

Docker Master Command Reference

Stop Googling every flag. Here is your definitive, copy-pasteable cheat sheet for managing the entire Docker lifecycle—from individual containers to Swarm clusters.

# basics

Core Operations

lifecycle

Daily Management

Everything you need to inspect your host, spin up isolated environments, pause them, and clean up the mess afterward.

PRO TIP

Use docker system prune -a to nuke all unused containers, networks, and images in one hit.

terminal
# 1. System & Info
$ docker --version
↳ Show Docker version
$ docker info
↳ Detailed Host + Engine info
$ docker ps
↳ List running containers
$ docker ps -a
↳ List all containers (including stopped)
$ docker inspect <ctr>
↳ Dump deep JSON details of a container
$ docker stats
↳ Live CPU/Memory streaming usage
$ docker top <ctr>
↳ View running processes inside a container
# 2. Running & Managing
$ docker run -it --name mybox alpine /bin/sh
↳ Start an interactive shell session
$ docker run -d --name web -p 8080:80 httpd
↳ Run detached, mapping host port 8080 to container 80
$ docker create --name test httpd
↳ Create container without starting it
$ docker start <ctr> | docker stop <ctr> | docker restart <ctr>
↳ Lifecycle controls
$ docker pause <ctr> | docker unpause <ctr>
↳ Freeze and resume execution state
# 3. Logs, Copy & Cleanup
$ docker logs -f --tail 100 <ctr>
↳ Stream the last 100 lines of logs
$ docker cp <ctr>:/path/in/ctr /path/on/host
↳ Copy files out of a container to your host
$ docker rename old_name new_name
↳ Change container name
$ docker rm <ctr> | docker rmi <image>
↳ Delete container / Delete image
# build

Images, Volumes & Networks

architecture

Assets & Wiring

Commands to pull blueprints (Images), persist your database files safely (Volumes), and wire containers together (Networks).

terminal
# 4. Images & Import/Export
$ docker images
↳ List downloaded images
$ docker pull httpd:latest
↳ Fetch an image from Docker Hub
$ docker tag httpd:latest myrepo/httpd
↳ Tag an image for your custom registry
$ docker push myrepo/httpd
↳ Upload image to registry
$ docker export <ctr> > ctr.tar
↳ Export a container's filesystem as a tar archive
$ docker save -o img.tar myimg | docker load -i img.tar
↳ Save/Load an entire image locally
# 5. Volumes (Storage)
$ docker volume ls | docker volume create myvol
↳ List or create managed volumes
$ docker run -d -v myvol:/data httpd
↳ Mount a managed volume to /data
$ docker run -d --mount type=bind,source=/host,target=/ctr alpine
↳ Explicit syntax to bind mount a host directory
$ docker run -d --mount type=tmpfs,destination=/app,tmpfs-size=70m alpine
↳ Mount a 70MB RAM-only temporary filesystem
# 6. Networks
$ docker network ls | docker network create mybridge
↳ List or create a bridge network
$ docker network connect mybridge <ctr>
↳ Attach a running container to a network
$ docker run -d --name web --network mybridge nginx
↳ Start a container directly on a specific network
# scaling

Compose & Swarm

orchestration

Multi-Container Tools

Use Compose to start multi-tier apps locally with a single YAML file. Use Swarm to deploy and distribute those apps across a cluster of servers.

terminal
# 7. Docker Compose (Local Orchestration)
$ docker-compose up -d
↳ Start all services in the background
$ docker-compose down
↳ Stop and remove all containers & networks
$ docker-compose logs -f
↳ Tail logs for the entire stack
$ docker-compose exec <svc> sh
↳ Open a shell into a specific service
$ docker-compose scale web=3
↳ Scale a specific service to 3 replicas
# 8. Docker Swarm (Cluster Orchestration)
$ docker swarm init --advertise-addr <IP>
↳ Initialize a Swarm manager
$ docker swarm join --token <token> <ip>:2377
↳ Join a node to the cluster
$ docker node promote <node> | docker node demote <node>
↳ Change a node's management role
$ docker node update --availability drain <node>
↳ Evict containers from a node (Maintenance mode)
$ docker service create --replicas 2 -p 80:80 --name myweb nginx
↳ Create a resilient service across the Swarm
$ docker service update --image nginx:1.25 myweb
↳ Perform a rolling update on a service
$ docker service rollback myweb
↳ Instantly revert the previous update<