Course outline · 0% complete

0/29 lessons0%

Course overview →

Housekeeping: disk usage and cleanup

lesson 4-3 · ~10 min · 13/29

Docker will fill your disk

Everything in this course so far accumulates: every build leaves layers behind, every stopped container keeps its writable layer, every pulled image stays until deleted, and the build cache grows without limit. On a working developer's machine this quietly reaches tens of gigabytes, and "no space left on device" breaking builds is one of the most common Docker problems on dev laptops and CI machines (CI is short for continuous integration: the automated machines that build and test every push) alike.

The overview command:

docker system df
TYPE            TOTAL   ACTIVE  SIZE     RECLAIMABLE
Images          24      3       11.2GB   9.8GB (87%)
Containers      11      2       420MB    390MB (92%)
Local Volumes   8       2       2.1GB    1.4GB (66%)
Build Cache     142     0       6.3GB    6.3GB

RECLAIMABLE is space used by things nothing currently references: stopped containers, unused volumes, dangling images (a term worth defining: image layers left with no tag, created when you rebuild myapp:v1 and the tag moves to the new build, orphaning the old one).

Docker is not available in this sandbox, so practice the cleanup routine in this simulated shell. Check usage, prune, and confirm the space came back.

Step 1/3: Start with the overview. Note the reclaimable column.

$ 

docker inspect: the full truth about one object

Cleanup's sibling skill is inspection. Every Docker object (container, image, volume, network) carries a full JSON description of how it is actually configured, and docker inspect prints it:

docker inspect web            # everything about the container: env vars,
                              # mounts, network IPs, restart policy, ports
docker inspect --format '{{.State.Status}}' web   # extract one field

This is the tool for "what is this container actually running with?" moments: which image exactly, which env values, which volume is mounted where. When a container someone else started behaves strangely, docker logs (lesson 2-3) tells you what it said, docker inspect tells you what it is.

Quiz

You run `docker system prune` and confirm. Which of these does it delete?

Problem

Which command prints a per-category summary (images, containers, volumes, build cache) of how much disk Docker is using and how much is reclaimable?