Docker Disk Space Cleanup

Docker Disk Space Cleanup (Hosts)

Docker data grows over time on host machines. Old rentals leave behind stopped containers, unused images, volumes, and build cache. If you don’t clean it up, the root disk fills up and deployments start failing.

circle-info

Run cleanup only when the server is not rented and you don’t need any old container data. If you’re unsure, stop here and do a disk usage check first.


1) Check disk usage

OS-level disk space (df -h)

This shows free space on each mounted filesystem.

df -h

You care mainly about / (root) and the partition that holds /var/lib/docker.

Docker-level disk usage (docker system df)

This shows what Docker is storing and how much is reclaimable.

docker system df

If you want more detail per image/container:

docker system df -v

This is the “reset Docker leftovers from previous rentals” command. It removes unused containers, images, networks, and unused volumes.

circle-exclamation

3) Individual cleanup commands (more control)

Use these when you want to clean a specific category. They’re safer for incremental maintenance.

Containers (stopped only)

Images (unused)

Remove dangling layers only:

Remove all unused images (same risk as system prune -a):

Volumes (unused)

Networks (unused)


4) Best practices for host maintenance

  1. Clean up between rentals or during planned downtime.

  2. Keep a safety buffer. Aim for 10–20 GB free on the root disk at all times.

  3. Check Docker usage regularly:

    • df -h

    • docker system df

  4. Prefer incremental cleanup first:

    • docker container prune

    • docker image prune

    • docker volume prune

  5. Use full cleanup only when needed:

    • docker system prune -a --volumes

  6. If disk usage keeps growing fast, investigate:

    • Large volumes created by renters.

    • Logs under /var/lib/docker/containers/*/*.log.

    • Build cache from frequent image rebuilds.

Last updated

Was this helpful?