Docker: "no space left on device" with plenty of disk free
Docker's own storage area is full of dangling images, stopped containers, build cache and unused volumes, even though the host filesystem looks healthy.
What you see
docker pull or docker build fails with no space left on device. df on / shows free space, or /var/lib/docker is on a filesystem that is genuinely full.
What is actually wrong
Accumulated layers and build cache. On a busy CI host this grows by gigabytes a day and nothing removes it automatically.
Codes and articles
The fix
Reclaim Docker's storage safely
Docker is out of space. Work from the safest reclaim to the most aggressive and stop when you have enough.
See where the space has gone before deleting anything.
docker system df -v | head -40sudo du -sh /var/lib/docker/*
Check whether /var/lib/docker is even on the filesystem you think it is.
df -h /var/lib/dockerdf -i /var/lib/docker
Overlay2 creates enormous numbers of small files, so a Docker host can exhaust inodes while showing free blocks — check -i as well as -h.
Remove stopped containers, unused networks and dangling images. This is the safe one.
docker system pruneClear the build cache, which is usually the biggest single consumer on a CI host.
docker builder prune -aRemove images not used by any container. Read the list before confirming.
docker image prune -a-a removes every image without a running container, including ones you intend to run later. On a machine with slow internet that is an expensive mistake.
Volumes last, and only after checking what is in them — this is where data lives.
docker volume ls -f dangling=truedocker volume prune
A dangling volume is one no container currently references. That includes the database volume of a container you stopped ten minutes ago.
Stop it recurring by capping the log driver, which grows without limit by default.
printf '{\n "log-driver": "json-file",\n "log-opts": { "max-size": "50m", "max-file": "3" }\n}\n' | sudo tee /etc/docker/daemon.jsonsudo systemctl restart docker
docker system dfdf -h /var/lib/docker
Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.