Reclaiming disk without losing data

Docker · lesson 25 of 31 · 3 min read

Find where the tens of gigabytes went and delete the right things, not your local databases.

Open this lesson in the learning hub

Key points

  • docker system df splits usage into images, containers, volumes and build cache. Read it before deleting anything.
  • Build cache is usually the biggest number. docker builder prune --filter until=168h keeps the recent, useful part.
  • docker system prune removes stopped containers, unused networks, dangling images and build cache. Volumes are kept.
  • docker system prune -a --volumes also removes every unused image and every unused named volume - your local database.
  • On CI runners prune on a schedule with a time filter. A cold cache on every build costs more than the disk it saved.

Example

# where did it go?
docker system df            # summary
docker system df -v         # per image, container, volume and cache record

# safe reclaim: stopped containers, dangling images, build cache
docker system prune

# keep the last week of build cache, drop the rest
docker builder prune --filter until=168h

# only unused images older than 30 days
docker image prune -a --filter "until=720h"

# this one deletes unused named volumes. no undo, no bin.
# docker system prune -a --volumes

Measure with df, prune with a filter, and think twice before --volumes.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Docker course, and every lesson in it is listed on the Docker contents page.