How do I docker empty cache?

To completely empty the Docker cache, you need to clear different layers of caching, including build cache, container layers, images, volumes, and networks. Below are different levels of cache clearing, depending on how aggressively you want to purge.

TL;DR: Which One Should You Use?

Command What It Does When to Use
docker builder prune -a Remove build cache only Force fresh rebuild without wiping images
docker system prune -a --volumes Remove everything unused Free up disk space, reset Docker state
docker rmi my-image-name Remove specific image If only one image is problematic
docker system prune -a --volumes --force + manual removal Full wipe (nuclear) If Docker is completely messed up
docker compose build --no-cache Rebuild without cache Fix bad cache issues

If you want to rebuild an image without using any cached layers:

docker builder prune -a
  • -a removes all cache, not just dangling cache.
  • This does not remove images or containers.

Use It When:

  • You want to force a fresh build without cached layers.

2. Remove Images, Containers, and Build Cache

If you want a full reset of your Docker environment:

docker system prune -a --volumes
  • -a → Deletes all unused images, not just dangling ones.
  • --volumes → Deletes unused volumes too.
  • ⚠️ Warning: This removes all unused containers, images, networks, and volumes.

Use It When:

  • You need a clean slate (e.g., fixing weird build issues).
  • You want to free up disk space.

3. Remove Specific Cached Layers

If you're debugging a single image, remove just that image and its build cache:

docker rmi my-image-name

If the image has dependent layers, force it:

docker rmi -f my-image-name

Use It When:

  • Only one image is causing trouble, and you don’t want to wipe everything.

4. Remove Everything (Nuclear Option)

If you want Docker completely reset as if it was never installed:

docker system prune -a --volumes --force
docker stop $(docker ps -aq) 2>/dev/null
docker rm $(docker ps -aq) 2>/dev/null
docker rmi $(docker images -q) 2>/dev/null
docker volume rm $(docker volume ls -q) 2>/dev/null
docker network rm $(docker network ls -q) 2>/dev/null

Use It When:

  • You really want to remove everything (including images, volumes, networks).

5. Prevent Cache During Build

If you want to disable cache for a single build, use:

docker compose build --no-cache

or

docker build --no-cache -t my-image .

This forces Docker to pull fresh dependencies and rebuild all layers.

Use It When:

  • You suspect stale cache is causing issues in your builds.

TL;DR: Which One Should You Use?

Command What It Does When to Use
docker builder prune -a Remove build cache only Force fresh rebuild without wiping images
docker system prune -a --volumes Remove everything unused Free up disk space, reset Docker state
docker rmi my-image-name Remove specific image If only one image is problematic
docker system prune -a --volumes --force + manual removal Full wipe (nuclear) If Docker is completely messed up
docker compose build --no-cache Rebuild without cache Fix bad cache issues