Card 05/ 07

ExampleDifficulty: Advanced1 min

Disk Usage Example: docker system df and docker system prune

Tens of gigabytes of old layers and containers, and the one flag that can delete data you cannot rebuild.

docker system df reports how much disk Docker is using for images, containers, volumes and the build cache (the stored results of earlier build steps), and docker system prune removes what nothing is using. Every build leaves layers and every run leaves a container, and neither is cleaned up for you, so on a machine that builds often the total reaches tens of gigabytes without anything appearing wrong.

bash
docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          48        3         14.2GB    12.8GB (90%)
Containers      21        2         1.1GB     1.0GB (95%)
Local Volumes   9         1         3.4GB     3.1GB (91%)
Build Cache     312       0         21.7GB    21.7GB (100%)

RECLAIMABLE is the column that matters: the space held by things nothing running is using. The build cache is usually the largest and the least missed, since losing it costs one slow build.

docker system prune removes stopped containers, unused networks, images with no tag, and the build cache. --volumes also removes anonymous volumes (volumes Docker created without a name) that no container uses:

bash
docker system prune
docker system prune --volumes   # only if you are sure

So read docker system df first, prune without --volumes by default, and add it only when you know that no unused volume holds data you need.