Table of Contents
Docker cache can silently grow and cause disk pressure, slow builds, or unpredictable image behavior. Forcing a cache cleanup is often necessary on long-running VPS setups.
Step 1: Clean Docker Build Cache Only
This removes unused build layers without touching containers or images.
docker builder prune
Force it without confirmation:
docker builder prune -f
To remove all build cache, including active layers:
docker builder prune -a -f
Step 2: Clean Image Layer Cache
Docker image layers are a major source of cache bloat.
docker image prune
Force remove all unused image layers:
docker image prune -a -f
This does not delete running containers.
Step 3: Clean Container Cache (Stopped Containers)
Stopped containers still hold writable layers and cache data.
docker container prune
Force mode:
docker container prune -f
Step 4: Clean Volume Cache (Data Destructive)
Volumes may contain leftover cache files from databases or applications. Only unused volumes are removed.
docker volume prune
Force remove unused volumes:
docker volume prune -f
Step 5: Clean Network Cache
Unused Docker networks can accumulate over time.
docker network prune
Force cleanup:
docker network prune -f
Step 6: Force Full Docker Cache Cleanup
This is the most aggressive cache cleanup method.
docker system prune -a --volumes
This removes build cache, image cache, stopped containers, unused volumes, and unused networks.
Step 7: Disable Cache During Docker Build
If builds behave inconsistently, bypass Docker cache completely.
docker build --no-cache -t my-image .
Optional Step: Check Cache and Disk Usage
Verify how much space was freed after cleanup.
docker system df
df -h