← All 45 books Docker, one command per page Get the full edition · £10
One command per page

Docker, one command per page

The twenty-seven commands that cover everything you do every day.


Steve Hodgkiss 8 commands

Know the command. Lose the fear.

Docker, one command per page

The twenty-seven commands that cover everything you do every day.


Set in Space Grotesk, Inter and JetBrains Mono (SIL Open Font License).

Command behaviour verified against the official Docker documentation: docs.docker.com

Your purchase is for personal use only. You do not have redistribution rights: please do not share, resell, or republish this book or its pages.

© 2026 Steve Hodgkiss. All rights reserved. Personal use only; no redistribution rights.

Edition 1.0 · stevehodgkiss.net

Contents

Contents


Part 1 · Everyday4
docker run5
docker ps6
docker images7
docker pull8
docker logs9
Part 2 · Building
docker build10
Part 3 · Compose
docker compose up11
Part 4 · Housekeeping
docker system prune12
Part 1 of 4
The loop you live in
1

Everyday

The seven commands that carry a normal day, and what each one really creates and leaves behind.


In this part
  1. 01docker run
  2. 02docker ps
  3. 03docker images
  4. 04docker pull
  5. 05docker logs

docker run creates a new container from an image and starts it, pulling the image first if it is missing. -d detaches, --name names it, and --rm removes the container automatically when it exits.

Docker · No. 01
Everyday

docker run

One image becomes one container

Imagenginx:alpineContainerwebexits with --rmcontainer removedA new container every run. --rm clears it on exit.

Let's say you've pasted a docker run line from a README fifty times and it worked. What it did: created a brand new container from the image and started it, downloading the image first if needed.

Nothing is reused from last time's container. Every run leaves a container behind, even after it exits. Add --rm on a scratch machine and it deletes itself on exit. Long-running services get a --name, so you can talk to them later.

Containers are disposable. Names are how you find them.

TRY IT NOW

docker run -d --name web -p 8080:80 nginx:alpine

docker ps lists containers, running ones only by default. The -a flag adds the stopped containers, which is where forgotten ones pile up, and --filter narrows the list to what you name.

Docker · No. 02
Everyday

docker ps

What's running, and what's been left behind

docker psweb Up 3 min1 runningdocker ps -aweb Upcache Exiteddb Exited (0)stopped containers stay on diskRunning is the default view. -a shows what piled up.

Let's say a port is taken and nothing seems to be using it. The first move is docker ps, the list of what's actually running, with the names you'll use in stop, logs, and exec. It's also where a container's port mapping shows up.

The trap is what the list leaves out. ps hides the stopped containers, and they stay on disk forever until you remove them. ps -a shows the whole pile, which is how you find the six forgotten pgtest containers. Filters help when the pile is big: --filter name=web, --filter status=exited. Everything docker does next starts with reading this list.

Run it before you type anything else.

TRY IT NOW

docker ps -a

docker images lists the top images on disk with their tags and sizes. Intermediate and dangling images stay hidden unless you pass -a, and listed sizes include shared parent layers.

Docker · No. 03
Everyday

docker images

What's on disk, and what it shares

node:22-alpine172 MBmyapp:1.0178 MBmyapp:2.0179 MBshared base layers, stored onceSizes include shared layers. -a adds the hidden ones.

Let's say the disk is filling and you suspect the images. docker images lists every top-level image with tag, ID and size. The reading half of housekeeping, and it costs nothing.

The list hides things: intermediate and dangling images only appear with -a, and <none> tags are usually old builds nobody renamed. Sizes look bigger than they are because images share base layers, stored once. Knowing what's on disk beats guessing at it.

Images share layers. The list under-reports the mess.

TRY IT NOW

docker images

docker pull downloads an image from a registry one layer at a time, reusing any layer already on disk. With no tag it pulls latest, and --platform chooses the architecture.

Docker · No. 04
Everyday

docker pull

Layers arrive once, then get reused

Registrydocker hublayer c3d4 newlayer a1b2 newlayer e5f6 cachedLocalnginx:alpineLayers already on disk are skipped, not downloaded twice.

Let's say the demo starts in two minutes and the network picks now to die. docker pull downloads the image layer by layer and stores it locally, so run has nothing left to fetch.

Layers you already have are skipped, across versions and across images, which is why a refreshed tag pulls in seconds. No tag means latest, and latest on your laptop and latest next month are different images. --platform pins the architecture.

Pull early. Pin the tag.

TRY IT NOW

docker pull nginx:alpine

docker logs shows what the main process printed to stdout and stderr. -f streams new lines as they arrive, --tail keeps it short, and it works on stopped containers too.

Docker · No. 05
Everyday

docker logs

What the container has been saying

webcontainerstdoutstderr10:02:01 listening on 8010:02:03 GET / 20010:02:04 warn: cache colddocker logs -f keeps streamingThe crash usually introduces itself here. Read before restart.

Let's say the container starts and dies three seconds later. Read what it said first: docker logs shows everything the main process printed to stdout and stderr.

-f streams new lines, tail keeps it short, --since 30m is gold at 3am. Logs belong to the container, so a crashed container's last words are still there for the reading. Apps logging to a file inside the container lose the file with the container.

Logs first. Restarts second.

TRY IT NOW

docker logs -f web

docker build turns a Dockerfile and a build context into an image. Unchanged instructions reuse cached layers, and everything after the first change rebuilds. -t names the result.

Docker · No. 06
Building

docker build

Turn the recipe into an image

FROM alpinecache hitCOPY package.jsoncache hitRUN npm cicache hitCOPY . . (changed)rebuilds from hereone change, everything below rebuildsStable instructions first. Volatile ones last.

Let's say every build takes four minutes and you've stopped shipping small fixes. The cache is the way out: docker build reuses a layer for every instruction whose inputs haven't changed.

The moment one instruction changes, its layer rebuilds, and everything after it loses the cache too, changed or not. That's why dependency files come before source. -t names the result. Reordering the file turns four minutes into forty seconds, permanently.

Cache is earned by instruction order.

TRY IT NOW

docker build -t myapp:1.0 .

docker compose up builds, creates, starts and attaches to every service in the Compose file, plus the network joining them. -d detaches so they keep running after the terminal closes.

Docker · No. 07
Compose

docker compose up

The whole application, one command

compose up -dwebdbcachenetwork app_defaultOne file builds, creates, starts and wires the stack.

Let's say local setup is five README steps. One compose file replaces it: services, ports, volumes, wiring. docker compose up builds, creates, starts and attaches to every service in one go.

-d detaches and leaves the stack running. The command is idempotent in the useful way: unchanged services stay up, changed ones get recreated. The hyphenated docker-compose is the old v1 binary; the space is the real spelling now.

One file, one command, the whole app.

TRY IT NOW

docker compose up -d

docker system prune removes stopped containers, unused networks, dangling images and unused build cache in one go, asking first. -a widens images to all unused ones, --volumes adds anonymous volumes.

Docker · No. 08
Housekeeping

docker system prune

The vacuum, aimed carefully

stopped containersunused networksdangling imagesbuild cachepruneasks first-a: all unused images--volumes: opt-in23.0+ stopped pruning them silentlyDangling by default. -a and --volumes when you mean it.

Let's say df says gigabytes are reclaimable. docker system prune clears stopped containers, unused networks, dangling images and build cache in one go, and asks before it touches anything.

-a widens images from dangling-only to every unused one. --volumes adds anonymous volumes, and there's no undo for data; Docker 23.0 stopped pruning them by default for exactly that reason. docker cp out anything you need before the y.

Read the prompt. It's a contract.

TRY IT NOW

docker system prune -a

Index

Index


docker build10
docker compose up11
docker images7
docker logs9
docker ps6
docker pull8
docker run5
docker system prune12