Code

Recovering 19 GB from Docker

2 min read

A 97 GB production server had reached 85% disk usage, with 82 GB used. The running stack was healthy. The job was to find stale Docker data without touching active services, databases, media, monitoring data, rollback images, or source code.

I started with an inventory:

df -h /
df -i /
docker system df
docker ps -a --size

The first clear target was 7.475 GB of unused build cache:

docker builder prune --all --force

The rest needed more care. I found 34 obsolete CI and test image tags left by browser tests, load tests, security checks, linters, and application builds. There were also images and volumes from retired WordPress, MariaDB, and communications services.

Before removing an image or volume, I checked that no container referred to it:

docker ps -aq --filter ancestor=IMAGE
docker ps -aq --filter volume=VOLUME

Only explicit, verified lists went into the removal commands:

docker image rm IMAGE_1 IMAGE_2
docker volume rm VOLUME_1 VOLUME_2

No containers were removed or restarted.

Checking the result

After the cleanup, I validated both Compose configurations, tested nginx, checked the development and production health endpoints, confirmed the Git worktrees were clean, and ran the disk audit again:

docker compose -f COMPOSE_FILE config --quiet
docker exec NGINX_CONTAINER nginx -t
curl --fail $health_url
git status --short --branch
docker system df
df -h /

Disk usage fell from 82 GB (85%) to 63 GB (65%). About 19 GB was recovered, leaving 35 GB available. Every health endpoint returned HTTP 200, and nginx and both Compose configurations passed validation.

The sequence was straightforward: inventory the host, check references, delete named targets, then verify the stack.