Skip to main content
Fix Docker "No Space Left on Device"

Fix Docker "No Space Left on Device"

KU
· Founder & Chief Editor
• 8 min read•Updated •61 views

Your build fails, your containers won't start, and df says the disk is full. Here's where Docker hides the gigabytes and how to get them back safely.

Key takeaways

  • Run docker system df to see what is reclaimable, then docker builder prune for build cache, docker image prune and docker container prune for leftovers.
  • Cap json-file logs with max-size in daemon.json, since rotation is off by default.
  • Keep --volumes out of automation, because it deletes anonymous volumes that can hold database data.

Fix Docker's "no space left on device" by running docker system df, then docker builder prune -f (build cache is usually the biggest reclaimable item), docker image prune -f and docker container prune -f. Then cap logs with max-size in /etc/docker/daemon.json, because the default json-file driver never rotates. Never automate --volumes.

Verified against

Docker Engine 29.9 (29.9.2, released 2026-10-20), against the docs.docker.com pruning, json-file logging driver, daemon data directory and Engine 29 release notes pages. Checked October 2026.

The error usually surfaces as a failed build, write /var/lib/docker/tmp: no space left on device, on a host nobody has touched in months. It almost never means your data is too big. It means Docker's housekeeping was never set up: old images, dead build cache, and container logs that have never rotated.

Where Docker actually eats disk

Docker's data-root is /var/lib/docker. On a fresh Docker Engine 29 install, the containerd image store is the default, so image contents and container snapshots live in /var/lib/containerd instead, while volumes and container logs stay under /var/lib/docker. Check both. Five things fill them up, roughly in order of how often they bite:

  • Images and layers. Every docker pull and docker build stacks layers. Old tags and intermediate layers stick around forever.
  • Build cache. BuildKit keeps it separate from images and it grows fast on busy CI. It's usually the biggest surprise.
  • Stopped containers. Each one keeps its writable layer until you remove it.
  • Volumes. Named and anonymous volumes hold real data. This is the one you can lose by being careless.
  • Container logs. With the default json-file driver, max-size is unlimited, so a chatty container writes an unbounded log file.

Diagnose before you delete

Start with Docker's own accounting. docker system df gives you the summary:

code
$ docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          42        6         28.3GB    22.1GB (78%)
Containers      11        3         1.2GB     980MB (81%)
Local Volumes   17        4         6.4GB     3.1GB (48%)
Build Cache     213       0         31.7GB    31.7GB (100%)

That RECLAIMABLE column is the whole story. In this example, 31.7GB of build cache is doing nothing and most of the image space is waste. Add -v to break it down per image, container, and cache record:

code
$ docker system df -v

Cross-check against the OS so you know Docker is the culprit and not something else on the box:

code
$ df -h /var/lib/docker /var/lib/containerd
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p1   98G   97G  0.5G  99% /

$ sudo du -sh /var/lib/docker/* /var/lib/containerd 2>/dev/null | sort -h | tail -5

On the classic storage driver, overlay2 is your image and container layers and buildkit is the cache. With the containerd image store, those layers show up under /var/lib/containerd. If /var/lib/docker/containers is huge, that's almost always log files.

The fixes, in the order we run them

1. Prune build cache first

This is the safest big win and the one most people forget. Build cache never contains data you care about, only reusable build steps, so clearing it costs you nothing but a slower next build:

code
$ docker builder prune -f
Total reclaimed space: 31.7GB

Run it before anything riskier. To keep recent cache and drop old, docker builder prune -f --filter until=168h clears anything older than a week.

2. Remove dangling and unused images

Dangling images are the untagged <none> layers left behind by rebuilds:

code
$ docker images -f dangling=true    # see them first
$ docker image prune -f

To go further and drop every image not used by any container, run docker image prune -a. It will re-pull anything you still use on the next deploy.

3. Clean up stopped containers

code
$ docker container prune -f
Deleted Containers:
3f9a...   7c21...
Total reclaimed space: 980MB

This only removes stopped containers. Running ones are never touched.

4. Fix container logs (the fix that actually sticks)

If du showed a fat containers directory, hunt the log:

code
$ sudo du -sh /var/lib/docker/containers/*/*-json.log | sort -h | tail -3
14G  /var/lib/docker/containers/a1b2.../a1b2...-json.log

You can truncate a single file live with sudo truncate -s 0 <file>, but that's a band-aid. The real fix is rotation. Per container:

code
$ docker run --log-opt max-size=10m --log-opt max-file=3 myimage

Or globally, so every new container inherits it. Edit /etc/docker/daemon.json:

JSON
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

Then sudo systemctl restart docker. Docker's docs are explicit that existing containers don't pick up the new logging configuration, so recreate them.

5. The blunt instrument, and where it bites

docker system prune sweeps stopped containers, dangling images, unused networks, and unused build cache in one shot:

code
$ docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - unused build cache

Add -a and it also removes every unused image. That's fine on a CI box.

The one to respect is --volumes. Volumes aren't pruned by default, and docker system prune --volumes removes unused anonymous volumes (named ones need docker volume prune --all). That sounds safe until you remember that images like postgres declare a VOLUME, so a database container started without a named volume keeps its data in an anonymous one. Stop that container during a deploy, run the prune, and the data is gone. Never put --volumes in an automated job. To clean volumes, list them with docker volume ls -f dangling=true and remove them by name.

Inode exhaustion: full disk with free space

Occasionally df -h shows space free but writes still fail. Check inodes:

code
$ df -i /var/lib/docker
Filesystem      Inodes  IUsed IFree IUse% Mounted on
/dev/nvme0n1p1  6.1M    6.1M  0     100%  /

Millions of tiny files from image layers can exhaust inodes before bytes run out. The same image and cache pruning fixes it, since each layer is a pile of small files.

Move or expand the data-root

If the box genuinely needs more space, point Docker at a bigger disk instead of fighting for scraps. Stop Docker, copy the directory, and set data-root in /etc/docker/daemon.json:

JSON
{
  "data-root": "/mnt/bigdisk/docker"
}
code
$ sudo systemctl stop docker
$ sudo rsync -aP /var/lib/docker/ /mnt/bigdisk/docker/
$ sudo systemctl start docker
$ docker info | grep "Docker Root Dir"

Verify the root dir before you delete the old copy. The catch on Engine 29: data-root does not move image and container data stored by the containerd image store. Move that by setting root in /etc/containerd/config.toml, per Docker's daemon docs.

Automate cleanup safely

The goal is a nightly job that reclaims the cheap stuff and never touches data. This is the crontab line we trust:

code
# /etc/cron.d/docker-prune
0 3 * * * root docker builder prune -f --filter until=168h && docker container prune -f && docker image prune -f

Cache older than a week, stopped containers, dangling images. No -a, no --volumes, nothing that can delete a running service or a database. If a build fails for a reason other than disk, our Docker troubleshooting guide covers the rest, and a tight .dockerignore keeps the build context from feeding the cache in the first place.

Questions people ask

Is docker system prune safe?

Mostly. By default docker system prune removes stopped containers, unused networks, dangling images, and unused build cache, and it does not touch volumes. Adding -a also deletes every unused image, which only costs re-pulls. The risky flag is --volumes, which removes unused anonymous volumes, where a database container without a named volume keeps its data. Keep that flag out of scripts.

Why is /var/lib/docker still full after pruning?

Usually logs. The json-file driver has no size cap by default, so check /var/lib/docker/containers/*/*-json.log with du, truncate the offender, and set max-size in daemon.json before recreating containers. Also check df -i for inode exhaustion, and on Docker Engine 29 fresh installs remember that images live in /var/lib/containerd, not /var/lib/docker.

How do I stop Docker logs from filling the disk?

Set rotation in /etc/docker/daemon.json with "log-opts": {"max-size": "10m", "max-file": "3"} and restart the daemon. That caps each container at roughly 30MB of logs. The setting applies only to containers created afterwards, so recreate existing ones. Per-container, pass --log-opt max-size=10m --log-opt max-file=3 to docker run, or set the same options under logging in Compose.

The call we'd make

Prune build cache first, every time, because it's the biggest and safest win. Set log rotation in daemon.json on every host so the problem stops coming back. Automate the safe prunes on a nightly cron. And keep --volumes out of anything automated, because the disk you save isn't worth the database you might lose.

Sources

Explore topics:DockerLinuxDevOps
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). Fix Docker "No Space Left on Device". DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/fix-docker-no-space-left

Markdown

[Fix Docker "No Space Left on Device"](https://www.devopsness.com/blog/fix-docker-no-space-left) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

586 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.