Introduction

When /var/lib/docker grows uncontrollably, the overlay2 storage driver often gets blamed as if it were the root cause. In reality, overlay2 is where several different storage problems become visible: unrotated logs, abandoned image layers, aggressive build cache growth, and containers writing too much into their writable layer. The fix is to identify which of those is dominating disk use before pruning blindly.

Symptoms

  • Host disk usage climbs until Docker reports no space left on device
  • docker system df shows large image, container, or build-cache consumption
  • New containers fail to start because Docker storage is full
  • Disk usage returns shortly after a generic prune because the root driver of growth remains

Common Causes

  • Container logs are unbounded under the default json-file driver
  • Build cache and old image layers accumulate without cleanup
  • Containers write large amounts of transient data into their writable layer
  • Unused images and stopped containers linger after repeated deploys

Step-by-Step Fix

  1. 1.Measure where the space is actually going
  2. 2.Start with Docker’s own accounting, then drill into the worst offenders rather than deleting everything blindly.
bash
docker system df
docker system df -v
  1. 1.Prune safely and intentionally
  2. 2.Remove unused layers and stale build cache only after checking whether they are really disposable.
bash
docker system prune -a --volumes
docker builder prune --all --force
  1. 1.Enable log rotation
  2. 2.Unbounded container logs are one of the most common reasons overlay2 or adjacent Docker storage explodes.
json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
  1. 1.Identify containers with unusually large writable layers
  2. 2.A single misbehaving container can dominate disk growth even when images and cache look reasonable.

Prevention

  • Configure Docker log rotation on every host
  • Prune build cache and unused resources on a controlled schedule
  • Watch writable layer growth, not only image count
  • Keep application temp data out of container writable layers when possible