Cheat sheet: Docker
Docker and Compose commands explained flag by flag, including pipe combos like docker ps -a | grep.
Each entry shows the command, a copy button, and what every part does: sub-command, flag, pipe, redirect and placeholder, in the order they appear. <placeholders> are the bits you replace.
- Whole sheet120
- Basics: images & containers11
- Volumes & networks4
- Find & inspect containers7
- Environment variables & container config12
- Software versions inside containers & images9
- Logs & shells5
- Run containers3
- Images4
- Cleanup6
- Docker Compose v27
- Container lifecycle & live changes10
- Builds, multi-platform & moving images11
- Volumes, networks & remote hosts in depth12
- Compose: more commands9
- Swarm mode10
Basics: images & containers11
docker version; docker infoIs Docker installed and running?What each part does
docker versionclient and server (daemon) versions; an error on Server means the daemon is not runningdocker infosystem-wide details: containers, images, storage driver, cgroup driver
docker run --rm hello-worldTest that everything worksWhat each part does
docker runcreate and start a container (pulls the image if missing)--rmremove the container when it exitshello-worldtiny test image that prints a greeting
docker imagesList local imagesWhat each part does
docker imagesalias of docker image ls: repository, tag, image ID, size
docker pull <image>:<tag>Download an imageWhat each part does
docker pulldownload from a registry (Docker Hub by default)<image>:<tag>e.g. nginx:1.27; without a tag it means :latest
docker ps; docker ps -aList running / all containersWhat each part does
docker psrunning containers-ainclude stopped ones
docker start <container>; docker stop <container>; docker restart <container>Start, stop, restart a containerWhat each part does
startstart a stopped container (keeps its data and settings)stopgraceful stop: SIGTERM, then SIGKILL after 10s (-t to change)restartstop then start
docker rm <container>Remove a containerCautionWhat each part does
docker rmdelete a stopped container; add -f to stop and delete a running one
docker rmi <image>:<tag>Remove an imageCautionWhat each part does
docker rmidelete a local image; -f forces it even if tagged elsewhere
docker rename <old-name> <new-name>Rename a containerWhat each part does
docker renamechange the container name
docker port <container>Which host port maps to the container?What each part does
docker portlist port mappings, e.g. 80/tcp -> 0.0.0.0:8080
docker login <registry>; docker logout <registry>Log in / out of a registryWhat each part does
docker loginstore credentials (Docker Hub if no registry is given)docker logoutremove them
Volumes & networks4
docker volume ls; docker volume create <name>; docker volume rm <name>List / create / remove volumesCautionWhat each part does
volume lsnamed volumes (persistent data)volume create <name>create one (docker run -v <name>:/path also creates it)volume rm <name>delete it and its data
docker run -d -v <volume>:<container-path> <image>Mount a named volume into a containerWhat each part does
-v <volume>:<container-path>data written to <container-path> survives container removal
docker network ls; docker network create <name>List / create networksWhat each part does
network lsbridge, host, none + your own networksnetwork create <name>user-defined bridge: containers on it reach each other by name
docker run -d --name <name> --network <network> <image>Run a container on a networkWhat each part does
--network <network>attach to that network; other containers can reach it as http://<name>
Find & inspect containers7
docker ps -a | grep <container-id>Find a container by ID or name in the full listWhat each part does
docker pslist containers (running only by default)-a--all: include stopped / exited containers too|pipe the table into grepgrep <container-id>keep only the row that contains that ID (a prefix like 3f2a is enough) or name
Tip Built-in alternative without grep: docker ps -a --filter id=<container-id> (or --filter name=<name>).
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"Only running containers, compact tableWhat each part does
docker psrunning containers--format "table …"Go template output; "table" adds column headers{{.Names}} {{.Status}} {{.Ports}}fields to show; \t separates columns
docker ps -a --filter status=exited --filter name=<name>Filter containers by state, name or imageWhat each part does
-aall containers--filter status=exitedonly exited ones (also: running, paused, restarting…)--filter name=<name>name contains <name>. Repeating --filter combines them
docker ps -qJust the IDs (for scripting)What each part does
-q--quiet: print only container IDs, one per line
docker inspect --format '{{.State.ExitCode}} OOMKilled={{.State.OOMKilled}}' <container>Why did it stop? Exit code and OOMWhat each part does
docker inspect <container>full JSON details of the container--format '…'Go template: print only the fields you ask for{{.State.ExitCode}}0 = clean exit, 137 = killed (often out of memory), 143 = SIGTERM{{.State.OOMKilled}}true if the kernel killed it for exceeding its memory limit
docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' <container>Container IP addressWhat each part does
range .NetworkSettings.Networksloop over every network the container is attached to{{.IPAddress}}print its IP on that network
docker stats --no-streamLive CPU / memory per containerWhat each part does
docker statsresource usage of running containers--no-streamprint one snapshot and exit instead of refreshing
Environment variables & container config12
docker exec <container> envPrint all environment variables of a running containerWhat each part does
docker exec <container>run a command inside the running containerenvprint every environment variable the container's processes see, KEY=value per line
Tip Needs a running container that has env (most images do; distroless ones don't). For a stopped container use the inspect version below.
docker exec <container> printenv <VAR>Print one environment variableWhat each part does
docker exec <container>run inside the containerprintenv <VAR>print only that variable's value; exit code 1 if it isn't set
docker inspect <container> --format '{{range .Config.Env}}{{println .}}{{end}}'Show env vars from the container config (works when stopped)What each part does
docker inspect <container>read the container's stored configuration; no exec needed--format '...'Go template to pick fields{{range .Config.Env}}loop over the Env list (from the image ENV, -e and --env-file){{println .}}print each KEY=value on its own line
Tip Shows the configured env, not variables a process exported at runtime. Secrets passed with -e are visible here: anyone with docker access can read them.
docker image inspect <image>:<tag> --format '{{json .Config.Env}}'Show env vars baked into an imageWhat each part does
docker image inspect <image>:<tag>metadata of a local image{{json .Config.Env}}the ENV values from the Dockerfile (PATH, versions...) as a JSON list
docker run --rm <image>:<tag> envPrint the env a fresh container would getWhat each part does
docker run --rmstart a throwaway container, removed when it exits<image>:<tag>the image to testenvoverride the command: just print the environment
docker compose exec <service> envPrint the env of a Compose serviceWhat each part does
docker compose exec <service>run inside the running service containerenvprint its environment, after .env and environment: substitution
Tip To check the values before starting anything, use docker compose config.
docker inspect <container> --format 'Entrypoint={{json .Config.Entrypoint}} Cmd={{json .Config.Cmd}}'Show the entrypoint and command a container runsWhat each part does
docker inspect <container>container config{{json .Config.Entrypoint}}the ENTRYPOINT (the program that always runs){{json .Config.Cmd}}the CMD (default arguments, replaced by what you type after the image name)
docker inspect <container> --format '{{json .Mounts}}' | jqShow mounts (volumes and bind mounts)What each part does
{{json .Mounts}}every mount: type, source on the host, destination in the container, read-only flag| jqpretty-print the JSON
docker inspect <container> --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}'Show the container's IP address(es)What each part does
{{range .NetworkSettings.Networks}}loop over every network the container is attached to{{.IPAddress}}its IP on that network
docker inspect <container> --format 'restart={{.HostConfig.RestartPolicy.Name}} memory={{.HostConfig.Memory}} cpus={{.HostConfig.NanoCpus}}'Show restart policy and resource limitsWhat each part does
{{.HostConfig.RestartPolicy.Name}}no, always, on-failure or unless-stopped{{.HostConfig.Memory}}memory limit in bytes (0 = unlimited){{.HostConfig.NanoCpus}}CPU limit in billionths of a CPU (1000000000 = 1 CPU, 0 = unlimited)
docker inspect <container> --format '{{json .State.Health}}' | jqShow the health check status and last resultsWhat each part does
{{json .State.Health}}status (starting / healthy / unhealthy), failing streak, and the output of the last checks| jqpretty-print
docker inspect <container> --format '{{json .Config.Labels}}' | jqShow labels (Compose project, versions, maintainers)What each part does
{{json .Config.Labels}}all labels as JSON, e.g. com.docker.compose.service and org.opencontainers.image.version| jqpretty-print
Software versions inside containers & images9
docker exec <container> cat /etc/os-releaseWhich OS and version is the container based on?What each part does
docker exec <container>run inside the containercat /etc/os-releasedistro name and version, e.g. Debian 12, Alpine 3.20, UBI 9
docker exec <container> sh -c 'dpkg -l 2>/dev/null || rpm -qa 2>/dev/null || apk info -v'List installed OS packages with versions (any distro)What each part does
sh -c '...'run a small shell script inside the containerdpkg -lDebian / Ubuntu packages and versions2>/dev/null ||hide the error and try the next tool if this one doesn't existrpm -qaRHEL / UBI / Amazon Linux packagesapk info -vAlpine packages with versions
docker exec <container> sh -c 'dpkg-query -W <package> 2>/dev/null || rpm -q <package> 2>/dev/null || apk info -v <package>'Version of one package in a containerWhat each part does
dpkg-query -W <package>Debian / Ubuntu: name and installed versionrpm -q <package>RHEL family: name-version-releaseapk info -v <package>Alpine: name-version
docker run --rm <image>:<tag> <program> --versionVersion of the app runtime in an imageWhat each part does
docker run --rm <image>:<tag>throwaway container from the image<program> --versione.g. node --version, python3 --version, java -version, nginx -v
docker image inspect <image>:<tag> --format '{{index .Config.Labels "org.opencontainers.image.version"}}'Image version labels (OCI annotations)What each part does
docker image inspect <image>:<tag>image metadata{{index .Config.Labels "..."}}read one label; the OCI version label is set by many official images and good pipelines
docker image inspect <image>:<tag> --format '{{.Id}} {{index .RepoDigests 0}} {{.Created}} {{.Os}}/{{.Architecture}}'Image ID, digest, created date and architectureWhat each part does
{{.Id}}local image ID{{index .RepoDigests 0}}registry digest (repo@sha256:...) to pin exactly this image{{.Created}}build date{{.Os}}/{{.Architecture}}platform, e.g. linux/amd64 or linux/arm64
docker inspect <container> --format '{{.Config.Image}} {{.Image}}'Which image (and digest) is a container running?What each part does
{{.Config.Image}}the name:tag it was started from{{.Image}}the exact image ID, so you can tell if :latest has moved since
docker manifest inspect <image>:<tag> | jq '.manifests[].platform'Check which platforms an image supports, without pullingWhat each part does
docker manifest inspectread the image manifest from the registry| jq '.manifests[].platform'list os/architecture of every variant (multi-arch images)
docker scout quickview <image>:<tag>Quick vulnerability overview of an imageWhat each part does
docker scout quickviewsummary of known CVEs by severity and base image update advice (Docker Scout plugin)<image>:<tag>local or registry image
Tip docker scout cves <image> lists every CVE. Trivy does the same without Docker's plugin.
Logs & shells5
docker logs -f --tail 200 -t <container>Follow the last 200 log lines with timestampsWhat each part does
docker logs <container>the container's stdout/stderr-f--follow: keep streaming new lines--tail 200start from the last 200 lines (alias -n)-t--timestamps: prefix each line with its time
docker logs --since 15m <container> 2>&1 | grep -i errorLogs from the last 15 minutes, errors onlyWhat each part does
--since 15monly lines from the last 15 minutes (also 1h30m or an RFC3339 time)2>&1merge stderr into stdout, so grep also sees error output| grep -i errorkeep lines containing "error", any case
docker exec -it <container> shOpen a shell inside a running containerWhat each part does
docker exec <container>run a command in a running container-i--interactive: keep stdin open-t--tty: allocate a terminalshthe command to run (use bash if the image has it)
docker exec -e <KEY>=<value> -w <dir> <container> <cmd>Run a one-off command with env and workdirWhat each part does
-e <KEY>=<value>set an environment variable for this command only-w <dir>working directory inside the container<cmd>command to run; wrap chains as sh -c "a && b"
docker cp <container>:<path> ./ ; docker cp ./<file> <container>:<path>Copy a file out of / into a containerWhat each part does
docker cp <container>:<path> ./container → current host directory;thendocker cp ./<file> <container>:<path>host → container
Run containers3
docker run -d --name <name> -p <host-port>:<container-port> <image>:<tag>Run a service in the background with a port and a nameWhat each part does
docker runcreate and start a container-d--detach: run in the background and print the ID--name <name>give it a fixed name instead of a random one-p <host-port>:<container-port>publish a container port on the host (binds all interfaces; use 127.0.0.1:<host-port>:… for local only)<image>:<tag>image to run (pin a tag, avoid latest)
docker run -it --rm <image> shThrow-away interactive containerWhat each part does
-itinteractive + terminal--rmdelete the container (and anonymous volumes) when it exitsshcommand to run instead of the image default
docker run -d -e <KEY>=<value> --env-file .env -v <host-path>:<container-path>:ro -m 512m --cpus 1 --restart unless-stopped <image>Env vars, volume and limitsWhat each part does
-e <KEY>=<value>set one environment variable--env-file .envload KEY=value lines from a file-v <host-path>:<container-path>:robind-mount a host folder, read-only-m 512mmemory limit (exceeding it → OOM kill, exit 137)--cpus 1at most one CPU worth of time--restart unless-stoppedrestart automatically unless you stopped it yourself
Images4
docker build -t <registry>/<image>:<tag> -f <Dockerfile> .Build and tag an imageWhat each part does
docker buildbuild an image (BuildKit)-t <registry>/<image>:<tag>name and tag for the result-f <Dockerfile>which Dockerfile (default ./Dockerfile).build context: the folder sent to the builder (.dockerignore trims it)
docker build --no-cache --pull --target <stage> --build-arg <KEY>=<value> -t <image>:<tag> .Clean rebuild of one stage with a build argWhat each part does
--no-cacheignore cached layers--pullalways check for a newer base image--target <stage>stop at a named stage of a multi-stage Dockerfile--build-arg <KEY>=<value>value for an ARG in the Dockerfile
docker tag <image>:<tag> <registry>/<image>:<tag> && docker push <registry>/<image>:<tag>Tag and push to a registryWhat each part does
docker tag <src> <target>add another name to an existing image&&only if tagging workeddocker push <target>upload it (run docker login <registry> first)
docker history --no-trunc <image>Image layers and what created themWhat each part does
docker historyone row per layer with its size--no-truncshow the full command that created each layer
Cleanup6
docker system dfHow much space Docker usesWhat each part does
docker system dfspace used by images, containers, volumes and build cache, plus how much is reclaimable
docker ps -q | xargs -r docker stopStop all running containersCautionWhat each part does
docker ps -qIDs of running containers|pipe them to xargsxargs -rpass them as arguments; -r: don't run if the list is emptydocker stopstop each one gracefully (SIGTERM, then SIGKILL after 10s)
docker ps -aq --filter status=exited | xargs -r docker rmRemove all exited containersCautionWhat each part does
-aqall containers, IDs only--filter status=exitedonly exited onesxargs -r docker rmremove them
Tip Same result: docker container prune
docker system prune -f --filter "until=24h"Remove unused data older than a dayCautionWhat each part does
docker system pruneremove stopped containers, unused networks, dangling images and build cache-f--force: no confirmation prompt--filter "until=24h"only things older than 24 hours
docker system prune -a --volumesRemove everything unused, including volumesDestructiveWhat each part does
-a--all: also every image not used by a container (not just dangling)--volumesalso unused volumes: this deletes data
docker builder prune -af --filter "until=24h"Remove build cache onlyCautionWhat each part does
docker builder pruneremove BuildKit build cache (image prune does not touch it)-aall cache, not only dangling-fno prompt--filter "until=24h"keep the last day of cache
Docker Compose v27
docker compose up -d --buildBuild and start everything in the backgroundWhat each part does
docker composeCompose v2 (plugin; not the old docker-compose binary)upcreate and start the services-ddetached--buildbuild images before starting
docker compose up -d --force-recreate --remove-orphans --waitRecreate cleanly and wait until healthyWhat each part does
--force-recreaterecreate containers even if nothing changed--remove-orphansremove containers for services no longer in the file--waitwait until services are running/healthy (implies -d)
docker compose logs -f --tail 100 <service>Follow logs of one serviceWhat each part does
logs <service>logs of that service (omit for all)-ffollow--tail 100start from the last 100 lines
docker compose exec <service> sh; docker compose run --rm <service> <cmd>Shell into a service / run a one-off taskWhat each part does
exec <service> shshell in the already-running service containerrun --rm <service> <cmd>start a new temporary container for a one-off command, removed afterwards
docker compose -f compose.yaml -f compose.prod.yaml -p <project> up -dUse several compose files and a project nameWhat each part does
-f compose.yaml -f compose.prod.yamlmerge files in order; later files override earlier ones-p <project>project name (prefix for container/network names)
docker compose configSee the final merged configWhat each part does
configparse, merge and print the effective compose file (great for checking env substitution)
docker compose down -vStop and remove the stack (and its volumes)DestructiveWhat each part does
downstop and remove containers and networks-valso remove named volumes declared in the file: deletes data
Container lifecycle & live changes10
docker top <container>Processes running inside a containerWhat each part does
docker topps output for the container's processes, as seen from the host (PIDs are host PIDs)<container>name or ID
docker diff <container>Files changed inside a container since it startedWhat each part does
docker difflist files added (A), changed (C) or deleted (D) in the container's writable layer
Tip Handy to find where an app writes data that should be in a volume.
docker kill -s <signal> <container>Send a signal to a containerCautionWhat each part does
docker killsend a signal to the main process (default SIGKILL)-s <signal>e.g. HUP to reload nginx config, TERM for a graceful stop
docker pause <container>; docker unpause <container>Pause and resume a containerWhat each part does
docker pausefreeze all processes (cgroup freezer); memory stays, no CPU useddocker unpauselet them run again
docker wait <container>Wait for a container to exit and get its exit codeWhat each part does
docker waitblock until the container stops, then print its exit code (useful in scripts)
docker update --memory 1g --memory-swap 1g --cpus 1.5 --restart unless-stopped <container>Change memory, CPU or restart policy of a running containerWhat each part does
docker updatechange settings live, no restart--memory 1g --memory-swap 1ghard memory limit; equal swap value means no extra swap--cpus 1.5at most 1.5 CPUs--restart unless-stoppednew restart policy
docker attach --sig-proxy=false <container>Attach to a container's main processWhat each part does
docker attachconnect your terminal to the main process's stdin/stdout--sig-proxy=falseso Ctrl+C doesn't kill the container; detach with Ctrl+P Ctrl+Q
Tip Usually you want docker logs -f or docker exec instead.
docker events --filter container=<container> --since 30mWatch Docker events liveWhat each part does
docker eventsstream of daemon events: create, start, die, oom, health_status, kill...--filter container=<container>only this container (also type=, event=, image=)--since 30minclude events from the last 30 minutes
docker commit -m "<message>" <container> <image>:<tag>Save a container's current state as an imageWhat each part does
docker commitsnapshot the container's filesystem into a new image-m "<message>"commit message<image>:<tag>name for the new image
Tip Good for debugging or forensics; for real images use a Dockerfile.
docker create --name <name> <image>:<tag>Create a container without starting itWhat each part does
docker createcreate the container (pull if needed) but don't run it--name <name>its name; start later with docker start
Builds, multi-platform & moving images11
docker build --build-arg <ARG>=<value> --target <stage> --no-cache -t <image>:<tag> .Build with build args, a target stage and no cacheWhat each part does
--build-arg <ARG>=<value>set an ARG declared in the Dockerfile (not for secrets: they stay in history)--target <stage>stop at this stage of a multi-stage build--no-cacherebuild every layer-t <image>:<tag>name the result.build context
docker build -f <path>/Dockerfile.prod -t <image>:<tag> .Use a different DockerfileWhat each part does
-f <path>/Dockerfile.prodDockerfile to use.build context (can differ from the Dockerfile's folder)
docker build --secret id=npmrc,src=$HOME/.npmrc -t <image>:<tag> .Pass a secret to a build without leaving it in the imageWhat each part does
--secret id=npmrc,src=...mount a file only during the RUN step that asks for itDockerfile sideRUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
docker buildx build --platform linux/amd64,linux/arm64 -t <registry>/<image>:<tag> --push .Build for several CPU architectures and pushWhat each part does
docker buildx buildBuildKit builder with multi-platform support--platform linux/amd64,linux/arm64build both (Intel/AMD servers and ARM like Graviton or Apple Silicon)--pushpush the multi-arch image straight to the registry
docker buildx ls; docker buildx create --name <builder> --useList and create buildx buildersWhat each part does
docker buildx lsbuilders and the platforms they supportdocker buildx create --usenew builder (docker-container driver) and make it the default
docker build --progress=plain -t <image>:<tag> .Build with plain progress output (CI logs)What each part does
--progress=plainfull, line-by-line output of every step instead of the collapsing TTY view
docker save -o <file>.tar <image>:<tag>Save an image to a file (no registry)What each part does
docker saveexport one or more images with all layers and tags-o <file>.tarwrite to a tar file
docker load -i <file>.tarLoad an image from a fileWhat each part does
docker loadimport images saved with docker save-i <file>.tarinput file (also reads .tar.gz)
docker save <image>:<tag> | gzip | ssh <user>@<host> 'gunzip | docker load'Copy an image to another host over SSHWhat each part does
docker save <image>:<tag>stream the image as tar| gzipcompress it| ssh <user>@<host> '...'send it to the other machinegunzip | docker loadunpack and load it there
docker export <container> -o <file>.tarExport a container's filesystemWhat each part does
docker exportflatten the container's filesystem into a tar (no layers, history or metadata)-o <file>.taroutput file
docker initGenerate a Dockerfile, compose file and .dockerignoreWhat each part does
docker initasks about your project (Node, Python, Go...) and writes starter Docker files
Volumes, networks & remote hosts in depth12
docker volume inspect <volume>; docker ps -a --filter volume=<volume>Where is a volume's data and who uses it?What each part does
docker volume inspectdriver, mountpoint on the host, labelsdocker ps -a --filter volume=<volume>containers using it
docker run --rm -v <volume>:/data:ro -v "$PWD":/backup alpine tar czf /backup/<volume>.tgz -C /data .Back up a volume to a tar fileWhat each part does
docker run --rmthrowaway helper container-v <volume>:/data:romount the volume read-only-v "$PWD":/backupmount the current host folderalpine tar czf ... -C /data .archive the volume contents into the host folder
Tip Stop the app first (or use its own dump tool) for consistent database backups.
docker run --rm -v <volume>:/data -v "$PWD":/backup alpine tar xzf /backup/<volume>.tgz -C /dataRestore a volume from a tar fileCautionWhat each part does
-v <volume>:/datamount the target volume read-writetar xzf ... -C /dataunpack the backup into it
docker volume prune -aRemove unused volumesDestructiveWhat each part does
docker volume prunedelete volumes no container uses-ainclude named volumes (without it, only anonymous ones on Docker 23+)
docker network inspect <network> --format '{{json .IPAM.Config}} {{range .Containers}}{{.Name}} {{.IPv4Address}}; {{end}}'Inspect a network: subnet and connected containersWhat each part does
docker network inspect <network>network details{{json .IPAM.Config}}subnet and gateway{{range .Containers}}...{{end}}each attached container with its IP
docker network connect <network> <container>; docker network disconnect <network> <container>Connect / disconnect a running container to a networkWhat each part does
docker network connectattach to another network (containers can be on several)docker network disconnectdetach
docker run --rm --network host <image>; docker run --rm --network none <image>Run with host or no networkingWhat each part does
--network hostshare the host's network stack: no port mapping, no isolation (Linux only)--network noneno network at all, only loopback
docker network prune -fRemove unused networksCautionWhat each part does
docker network prunedelete networks no container uses-fno prompt
docker context create <name> --docker host=ssh://<user>@<host>; docker context use <name>Run docker commands against a remote hostWhat each part does
docker context createsave a named connection to another Docker daemon--docker host=ssh://<user>@<host>connect over SSH (no exposed TCP port needed)docker context use <name>make it the default; docker context use default to come back
DOCKER_HOST=ssh://<user>@<host> docker psOne-off command on a remote daemonWhat each part does
DOCKER_HOST=ssh://...point this one command at another daemondocker psany docker command
cat /etc/docker/daemon.json; journalctl -u docker -n 100 --no-pagerCheck the daemon config and its logsWhat each part does
/etc/docker/daemon.jsondaemon settings: log driver and rotation, registry mirrors, data-root, address poolsjournalctl -u dockerthe daemon's own logs (start errors, pull failures)
docker info --format '{{.DockerRootDir}} {{.Driver}} {{.LoggingDriver}} {{.CgroupDriver}}'Where does Docker store its data?What each part does
{{.DockerRootDir}}data directory, usually /var/lib/docker{{.Driver}}storage driver (overlay2){{.LoggingDriver}}default log driver (json-file, local, journald){{.CgroupDriver}}systemd or cgroupfs
Compose: more commands9
docker compose ps -aStatus of the stack's containersWhat each part does
docker compose pscontainers of this project: service, state, health, ports-ainclude stopped ones
docker compose restart <service>; docker compose stop <service>Restart / stop one serviceWhat each part does
restart <service>restart the container (config changes need up -d instead)stop <service>stop without removing
docker compose build --pull <service> && docker compose up -d <service>Rebuild images and recreateWhat each part does
build --pullrebuild, pulling newer base imagesup -d <service>recreate the container with the new image
docker compose pullPull newer images for all servicesWhat each part does
docker compose pulldownload the image of every service; follow with up -d to use them
docker compose up -d --scale <service>=3Run several replicas of a serviceWhat each part does
--scale <service>=3run 3 containers of the service (don't fix a host port or container_name)
docker compose --profile <profile> up -dStart optional services with a profileWhat each part does
--profile <profile>also start services marked profiles: [<profile>], e.g. debug or tools
docker compose watchRebuild automatically when files changeWhat each part does
docker compose watchsync or rebuild services on file changes, per the develop.watch section
docker compose top; docker compose imagesProcesses and images of the stackWhat each part does
docker compose topprocesses in each service containerdocker compose imagesimage and tag each container uses
docker compose cp <service>:<path> ./Copy a file out of a serviceWhat each part does
docker compose cplike docker cp, by service name
Swarm mode (services & stacks)10
docker swarm init --advertise-addr <ip>Turn this host into a swarm managerWhat each part does
docker swarm initcreate a single-node swarm with this host as manager--advertise-addr <ip>the address other nodes use to reach it
docker swarm join-token workerGet the join command for workersWhat each part does
join-token workerprint the docker swarm join command (use manager for extra managers)
docker node lsList nodesWhat each part does
docker node lsnodes, status, availability and manager status
docker service create --name <service> --replicas 3 -p 80:80 <image>:<tag>Create a replicated serviceWhat each part does
docker service createa long-running service the swarm keeps alive--replicas 33 tasks spread over the nodes-p 80:80publish through the routing mesh on every node
docker service ls; docker service ps <service>List services and where their tasks runWhat each part does
docker service lsservices with replicas running/desireddocker service ps <service>each task, its node, state and errors
docker service scale <service>=5Scale a serviceWhat each part does
scale <service>=5set the number of replicas
docker service update --image <image>:<new-tag> <service>; docker service rollback <service>Rolling update to a new image, and roll backWhat each part does
service update --imagerolling replace of tasks with the new imageservice rollbackgo back to the previous spec
docker service logs -f <service>Logs of all tasks of a serviceWhat each part does
docker service logsaggregated logs from every task-ffollow
docker stack deploy -c compose.yaml <stack>; docker stack rm <stack>Deploy and remove a stack from a compose fileCautionWhat each part does
stack deploy -c compose.yaml <stack>create or update all services in the filestack rm <stack>remove the stack's services and networks
printf '%s' "$VALUE" | docker secret create <name> -Store a secret for servicesWhat each part does
printf '%s' "$VALUE"the secret value without a trailing newlinedocker secret create <name> -store it encrypted in the swarm; services mount it at /run/secrets/<name>
Nothing matches.
My DevOps Playbook by Angelo John Calleja