Clearing Docker Cache

Clearing Docker Cache

Docker cache can accumulate over time, taking up significant disk space. Here are the most effective commands to clean up Docker cache and free up storage.

Quick Cleanup Commands

Complete System Cleanup

docker system prune -a

What it does: Removes all unused containers, networks, images (both dangling and unreferenced), and build cache. The -a flag ensures that all unused images are removed, not just dangling ones.

⚠️ Warning

This is aggressive and will remove all unused Docker resources. Make sure you don't need any stopped containers or unused images.

Image Cleanup Only

docker image prune

What it does: Removes only dangling images (intermediate layers that are no longer referenced by any tagged image).

More Targeted Cleanup Options

Remove Unused Containers

docker container prune

Remove Unused Networks

docker network prune

Remove Unused Volumes

docker volume prune

Remove Build Cache

docker builder prune

Check Disk Usage

Before cleaning up, you can check how much space Docker is using:

docker system df

This shows:

Best Practices

When to Use Each Command