Freeing Disk Space from Docker (Overlay2 Cleanup)

Docker is great—until your disk mysteriously fills up.
In my case, /var/lib/docker had grown to 350+ GB, almost entirely due to the overlay2 storage driver.

This post walks through how to safely identify the problem, reclaim the space, and verify Docker is healthy afterward.

1. Identify Where the Space Is Going

Start by checking disk usage at a high level:

sudo du -xh --max-depth=1 /var/lib | sort -h

Start by checking disk usage at a high level:

sudo du -xh --max-depth=1 /var/lib/docker | sort -h

Example output:

4.0K	/var/lib/docker/runtimes
4.0K	/var/lib/docker/swarm
4.0K	/var/lib/docker/tmp
4.0K	/var/lib/docker/trust
12K	/var/lib/docker/containers
16K	/var/lib/docker/plugins
84K	/var/lib/docker/volumes
344K	/var/lib/docker/network
26M	/var/lib/docker/image
107M	/var/lib/docker/buildkit
350G	/var/lib/docker/overlay2
351G	/var/lib/docker

At this point it’s clear: overlay2 is the culprit.

2. Why overlay2 Gets So Big

Docker uses overlay2 to store:

  • Image layers
  • Container writable layers
  • Intermediate filesystem state

Over time, especially on development machines or CI hosts, these layers can accumulate due to:

  • Rebuilt images
  • Abandoned containers
  • Interrupted builds
  • Long-running systems without pruning

3 Stop Docker Before Manual Cleanup

sudo systemctl stop docker
sudo systemctl is-active docker

Make sure it’s fully stopped before proceeding.

4. Remove the Overlay2 Data

⚠️ This removes all Docker images, containers, and layers.
Only do this if you’re okay with Docker starting fresh.

sudo rm -rf /var/lib/docker/overlay2

This is equivalent to a full reset of Docker’s storage backend.

5. Restart Docker

Bring Docker back up:

sudo systemctl start docker

Confirm Docker is using overlay2 again:

 docker info | grep -i storage
 Storage Driver: overlay2

Docker will automatically recreate the directory structure as needed.

6. Verify Disk Space Was Reclaimed

Finally, confirm that the space is back:

df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs            32G     0   32G   0% /dev/shm
tmpfs            13G  768K   13G   1% /run
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/sda3       1.5T  102G  1.3T   8% /