---
title: "docker builder prune — Safe Disk Recovery"
tags: [docker, devops, disk, ops]
sources: [99 Daily/2026-04-29.md]
created: 2026-04-30
updated: 2026-04-30
---

# docker builder prune — Safe Disk Recovery

`docker builder prune` removes the **build cache only** — it does not touch running containers, active images, named volumes, or networks. It is safe to run on a live production server when disk space is critically low.

## What It Removes

| Resource | Removed? |
|----------|---------|
| Build cache layers | Yes |
| Dangling (untagged) images | No (use `docker image prune`) |
| Running containers | No |
| Stopped containers | No |
| Named volumes | No |
| Networks | No |

## Commands

```bash
# Remove all build cache (interactive confirmation)
docker builder prune

# Remove all build cache without prompt — safe for scripts
docker builder prune -f

# Check how much space the build cache occupies first
docker system df
```

## When to Use

- Disk alert on a server; running containers must stay up
- After a large image build that left behind many intermediate layers
- Routine maintenance in CI environments between build runs

## What to Run Instead for More Aggressive Cleanup

```bash
# Remove dangling images (untagged) — safe if nothing references them
docker image prune

# Remove stopped containers + dangling images + unused networks
docker system prune

# Everything above + unused volumes — DESTRUCTIVE, confirm before running
docker system prune --volumes
```

> [!warning] `docker system prune --volumes` removes named volumes
> Named volumes may contain persistent data (databases, uploads). Never run this without confirming what volumes exist: `docker volume ls`.

## Related

- [[wiki/architecture/docker-compose-patterns|docker-compose-patterns]] — Docker Compose production patterns
- [[wiki/concepts/docker-compose-cpu-limits-env|docker-compose-cpu-limits-env]] — CPU limit pitfalls per environment
