When working with Docker, build cache can accumulate over time, taking up valuable disk space. If you want to free up space and remove unnecessary build cache, you can use Docker's built-in pruning commands. This tutorial explains how to remove Docker build cache.
Before removing the build cache, it's a good idea to check the current disk usage by running:
docker system df
This command will display the total disk usage of Docker resources, including images, containers, local volumes, and build cache. The output may look like this:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 2 0 467.6MB 467.6MB (100%)
Containers 0 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 5 0 545B 545B
From this output, you can see that the build cache is taking up some space, and it's fully reclaimable.
To remove Docker build cache, run the following command:
docker builder prune -f -a
-f
- confirms the action without prompting for user input.-a
- remove all unused build cache, not just dangling ones. Dangling build cache refers to cached layers that are no longer associated with any build or image. By default, the command removes only dangling cache layers. However, using-a
removes all unused build cache, including those that could still be used in future builds but are currently not in use.
Leave a Comment
Cancel reply