Fix Docker No Space Left on Device Without Deleting Your Volumes

Updated on Nov 30, 2026
Mila H
8 MINS READ
Table of Contents
Docker No Space Left on Device

Seeing Docker no space left on device is stressful. Many guides tell you to run docker system prune -a --volumes. On a server with a database, that command can be risky. This quick fix shows you how to find what uses the space, remove only safe data, and keep your volumes.

Step 1: Check Disk Blocks and Inodes

This error can have two causes, which are no free space or no free inodes. Inodes are the file slots on a disk. You can check both with the commands below:

Bash
df -hdf -i
  • If Use% is 100% in df -h, the disk blocks are full.
  • If IUse% is 100% in df -i, you have too many small files. Free space can still show as available.

You can find which mount is full with the commands below. Docker usually stores data in /var/lib/docker:

Bash
df -h /var/lib/dockersudo du -xh /var/lib/docker --max-depth=1 | sort -h

Tips: If you do not have a Linux server yet for Docker work, a Linux VPS with NVMe storage and full root access gives you a clean base to test these steps.

Step 2: Check What Docker Is Using

Now check how much space Docker itself uses. The docker system df command shows the size of your images, containers, volumes, and build cache. It helps you find what takes the most space, and it is the main command for docker system df reclaim space tasks. Run it before you delete anything:

Bash
docker system dfdocker system df -v

Here are the four types of data:

Type What it holds Safe to clean?
Images Downloaded and built images Unused ones, yes
Containers Running and stopped containers Stopped ones, after a check
Local Volumes App data, such as databases No, not without a check
Build Cache Saved build steps Yes, it is rebuilt when needed

The RECLAIMABLE column shows how much space Docker says you can free. Be careful with the number for volumes. A volume that no container uses right now can still hold your only copy of the data.

Step 3: Decide What Is Safe to Remove

Not everything Docker stores is safe to delete. Build cache and unused images are easy to get back. Volumes and some logs may hold data you need. Use the table below to match what you see with the right action:

What you see Common cause Check with Safe action
Large Build Cache Many builds docker system df docker builder prune
Large Images Old image versions docker images docker image prune -a
One huge *-json.log file No log limit du on the log path Set log rotation, then truncate
IUse% at 100% Millions of small files df -i Find and clean the folder with many files
Large Local Volumes App or database data docker volume ls Do not delete. Move or expand disk

Step 4: Clean the Docker Build Cache

When the "docker build cache disk full" problem happens, it is the safest one to fix. The build cache only makes builds faster. If you delete it, Docker makes it again the next time you build.

You can remove cache that is older than 24 hours with:

Bash
docker builder prune --filter "until=24h"

If you need more space, remove all unused cache:

Bash
docker builder prune -a

Check the results with the commands below:

Bash
docker system df

Step 5: Clean Unused Images and Stopped Containers

Old images and stopped containers also take up space on your disk. Most of them are safe to remove, but you must check them first. List what you have with the command below:

Bash
docker ps -a --filter "status=exited"

Then, remove stopped containers and unused images:

Bash
docker container prunedocker image prune -a

docker image prune -a removes images that no container uses. Docker will download or rebuild them later if needed.

Step 6: Find and Limit Large Container Logs

Container logs can grow very large over time. By default, Docker does not limit their size. A single busy container can fill your disk with log files. First, find the biggest logs with:

Bash
sudo sh -c 'du -h /var/lib/docker/containers/*/*-json.log | sort -h | tail -n 5'

Then, find the log file of one container:

Bash
docker inspect --format '{{.LogPath}}' your-container

Now run the command below to empty the log without deleting the file:

Bash
sudo truncate -s 0 "$(docker inspect --format '{{.LogPath}}' your-container)"

At this point, you must set up log rotation. This tells Docker to keep logs small. Open the Docker config file:

Bash
sudo nano /etc/docker/daemon.json

If the file is empty or new, paste this:

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

Note: If the file already has settings, do not delete them. Add only the log-driver and log-opts lines inside the existing { }, and put a comma between each setting.

This keeps up to 3 log files of 10 MB each for every container.

Save the file and exit. Then, check that the JSON is valid:

Bash
sudo python3 -m json.tool /etc/docker/daemon.json

If you see your settings printed back, the file is correct. Next, restart Docker:

Bash
sudo systemctl restart docker

Restarting Docker stops your containers unless live-restore is on. Do this in a quiet time.

The new limit only applies to new containers. Existing containers keep their old settings, so you must recreate them. Verify one container:

Bash
docker inspect --format '{{.HostConfig.LogConfig}}' your-container

You should see max-size and max-file in the output.

Step 7: Check Your Volumes

Volumes store your app data, such as databases and uploaded files. If you delete a volume, you may lose that data. So you must check what each volume holds before you run any cleanup command on it.

List volumes and check their size with the commands below:

Bash
docker volume lsdocker system df -v

Find which container uses a volume:

Bash
docker ps -a --filter volume=your_volume_name

Check where a volume is stored:

Bash
docker volume inspect your_volume_name

On Docker 23 and later, docker system prune --volumes removes only unused anonymous volumes. Named volumes stay safe unless you run docker volume prune -a. But anonymous volumes can also hold database data. So the rule is to check what each volume holds before you run any volume prune command.

Never run this on a server with real data:

Bash
docker volume prune -a

Tips: If your data is large and keeps growing, you can move it to bigger storage. A Storage VPS with 1 TB to 4 TB of HDD is a good place for backups and archives, so your main disk stays free.

Step 8: Disk Usage Before and After Cleanup

Here is an example of a safe cleanup. First, we check the disk usage, remove only the safe data, and then check again. The numbers come from a test server, so yours will differ. Notice that the volumes stay the same.

#Before: TYPE            TOTAL   ACTIVE   SIZE      RECLAIMABLEImages          18      4        9.2GB     6.8GB (73%)Containers      6       4        1.1GB     120MB (10%)Local Volumes   5       3        14.5GB    2.1GB (14%)Build Cache     142     0        11.4GB    11.4GB df -h /var/lib/docker# /dev/vda1  60G  57G  1.2G  98% /
#After: TYPE            TOTAL   ACTIVE   SIZE      RECLAIMABLEImages          4       4        2.4GB     0B (0%)Containers      6       4        1.1GB     120MB (10%)Local Volumes   5       3        14.5GB    2.1GB (14%)Build Cache     0       0        0B        0B df -h /var/lib/docker# /dev/vda1  60G  31G  26G  55% /

The Local Volumes line has the same size as before. This means we did not remove any volumes, so your data is still there.

Step 9: Rebuild the App and Verify the Database

After the cleanup, you must rebuild your app to make sure everything still works. This also checks that your database data is still there. Do not use the -v option, because it deletes your volumes:

Bash
docker compose builddocker compose up -d

Check that the containers run:

Bash
docker compose psdocker compose logs --tail 50

Check that the volume is still attached and has data:

Bash
docker volume lsdocker compose exec db ls -lh /var/lib/postgresql/data

Change db and the path in the command to match your own database. Then, open your app and check that your old data is still there.

Note: If this happens on a Coolify server, the same disk checks also apply. Check the Coolify troubleshooting guide for stuck builds and deploy problems.

Free Docker Disk Space Safely: Cache, Logs, and Images

Cleaning the disk once is not enough. Build cache and logs grow again with time. A few simple checks will keep your server healthy and stop this error from coming back:

  • Set log rotation in daemon.json.
  • Run docker builder prune --filter "until=168h" once a week.
  • Check df -h and docker system df.
  • Keep backups of important volumes on another server.

If your disk is always near full after cleanup, your real data is growing. At that point, you must pick a plan with more disk. Compare NVMe sizes on a Linux VPS plan or move backups to a Storage VPS.

Conclusion

To fix Docker no space left on device, run df -h and df -i to check disk space and inodes. Then, run docker system df to see what uses the space. Next, clean the build cache, unused images, and big logs. Keep your volumes unless you are sure you can delete them. Last, set up log rotation and rebuild your app to check that your database is still there.

No, not by default. With --volumes, it removes only unused anonymous volumes on Docker 23 and later.

Yes. Docker will rebuild it. Your next build may be slower.

The space may be used by logs, other apps, or inodes. Check df -i and du.

No. You must recreate the containers to apply the new limit.

No. Only docker compose down -v deletes them.

Only if you checked that every unused volume is disposable.