Your Docker environment suddenly runs out of disk space. Image builds start failing, containers cannot write files, and your application begins reporting storage errors.
The obvious solution might be to delete old images or run docker system prune. But cleaning up without understanding the problem can remove useful build cache, stop development workflows, or delete data you intended to keep.
The better approach is to find which filesystem is full, identify the Docker resources consuming space, and clean up only what you no longer need.
1. Check Whether the Host Disk Is Actually Full
Start by checking the available disk space on your system:
df -h
This shows filesystem capacity, used space, and available space. Look for the filesystem that has reached or is approaching its capacity limit.
Also check inode usage:
df -i
A filesystem can run out of inodes when it contains a very large number of files, even if some storage capacity remains available.
This distinction matters because a Docker build can fail with a “no space left on device” error when the problem is inode exhaustion rather than a lack of free gigabytes.
Remark: Docker's storage report and your host's filesystem report answer different questions. df -h shows filesystem usage, while Docker's commands report storage associated with the Docker daemon.
2. Find Out How Much Space Docker Uses
Once you know which filesystem is affected, inspect Docker's storage usage:
docker system df
The output groups storage into images, containers, local volumes, and build cache. It also reports how much space Docker considers reclaimable.
For a more detailed breakdown, run:
docker system df -v
This helps identify large images, containers with substantial writable layers, unused resources, and volumes that might need further investigation. Image size also requires careful interpretation because multiple images can share the same underlying layers.
If Docker reports substantial usage, investigate the largest category before removing anything. If Docker's totals appear small compared with the host's disk usage, look beyond Docker's ordinary image and container accounting.
3. Check Docker Build Cache
Build cache is a common source of storage usage on machines that build images frequently.
Docker and BuildKit retain intermediate build results to speed up future builds. Multiple projects, repeated builds, and changing dependencies can accumulate cache over time.
If you use Docker Buildx, inspect the selected builder's cache:
docker buildx du
This shows build-cache records, their sizes, last access information, and whether Docker considers them reclaimable.
If you use multiple builders, inspect the relevant builder rather than assuming this command covers every builder in your environment.
Cache is often a reasonable cleanup target when disk space is limited, but deleting it means Docker may need to rebuild those layers during subsequent builds.
Remark: Do not assume that deleting images has removed all build cache. Images and build-cache records have related but distinct lifecycles.
4. Check Container Logs and Writable Layers
A container can consume disk space through generated files and logs, even when its image is relatively small.
First, inspect containers and their writable-layer sizes:
docker ps -as
The SIZE column helps identify containers that have accumulated substantial writable-layer data. It does not include every source of storage associated with a container, so a small writable layer does not rule out large logs or mounted data.
Investigate container logs
Docker's default json-file logging driver does not enable log rotation by default. Applications that produce large amounts of output can therefore consume substantial disk space.
Check a container's logging driver and log path:
docker inspect --format='driver={{.HostConfig.LogConfig.Type}} log={{.LogPath}}' CONTAINER
Replace CONTAINER with the container name or ID. If the logging driver stores local files, inspect the relevant log file's size using appropriate host-level tools and permissions.
For future prevention, configure log rotation or consider Docker's local logging driver, which performs rotation by default.
Remark: Avoid manually deleting or truncating Docker-managed log files while Docker is running. Diagnose the log driver and use supported logging configuration instead.
5. Inspect Volumes and Bind Mounts
Volumes and bind mounts can hold large amounts of data outside a container's writable layer.
A database container might have a small writable layer while its database files occupy many gigabytes in a mounted volume. Similarly, a bind mount can point to a large directory on the host filesystem that does not appear as ordinary container-layer usage.
List Docker volumes:
docker volume ls
Inspect the mounts attached to a container and determine whether they reference volumes or host directories.
Before removing anything, identify what the data contains and whether the application still needs it. Database files, uploads, and persistent application state should not be treated as disposable simply because a volume is currently unused by a running container.
Remark: An unused volume is not necessarily unimportant. Back up required data and verify that no application depends on it before pruning volumes.
6. When Docker's Report Does Not Explain the Disk Usage
Sometimes docker system df does not account for the storage problem you see on the host.
Possible causes include large files outside Docker's managed storage, bind-mounted directories, container logs, other applications using the same filesystem, or storage maintained by Docker Desktop's virtual machine.
On Linux, find Docker's configured data directory:
docker info --format '{{.DockerRootDir}}'
You can then use read-only filesystem tools to inspect that directory and its parent filesystem. The default location is commonly /var/lib/docker, but installations can use a different path and storage backend.
Do not manually delete files from Docker's internal storage directories. Their contents are managed by Docker, and deleting files directly can corrupt the environment.
What about Docker Desktop?
Docker Desktop runs Docker inside a Linux environment and stores its data in a virtual disk. The space reported inside Docker may not match the virtual disk's apparent size on the host.
If Docker's resource usage looks reasonable but the host still has limited storage, inspect Docker Desktop's storage settings and the available disk-reclamation options for your version. Do not manually remove or modify its virtual disk files.
7. Choose the Cleanup Command Only After Diagnosing the Cause
Once you know what is consuming space, select the cleanup operation that matches the problem.
| Identified problem | Possible action |
|---|---|
| Unneeded stopped containers | docker container prune |
| Unused images | docker image prune |
| Unused build cache | docker builder prune |
| Unused volumes | docker volume prune |
Each operation has a different scope. For example, the default image-prune command removes dangling images, while broader options can remove additional unused images. Volume cleanup can destroy data that you still need.
Review the resources targeted by the chosen command before confirming it. If the disk is critically full, prioritize disposable resources with a clear storage impact rather than running the broadest prune command automatically.
Conclusion
When Docker fills your disk, deleting images should not be the first step. Start with the host filesystem, inspect Docker's storage breakdown, check build cache, examine container logs and writable layers, and investigate volumes or bind mounts.
If Docker's reported usage does not explain the host's disk consumption, look at the configured data directory and any virtual disk used by Docker Desktop.
The safest cleanup strategy is simple: measure first, identify the cause, and remove only what you understand and no longer need.



