I am running a lot of builds using Docker in MacOS. Eventually, a lot of build cache is accumulating, e.g. this is what I see in docker system df
:
YPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 22 0 9.67GB 9.67GB (100%)
Containers 0 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 1006 0 258GB 258GB
Is there a way to clean items from the build cache? I can see detailed list of them, e.g.:
CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
045834a7a6e9 regular 11.1MB 3 weeks ago 0 false
114ca5b7280f regular 114MB 3 weeks ago 0 false
27d6fcbb531d regular 1.65kB 3 weeks ago 0 false
3042a2a59d4f regular 553kB 3 weeks ago 0 false
3d70c1a312eb regular 468MB 3 weeks ago 0 false
658aaefc4cdd regular 209MB 3 weeks ago 0 false
7d5b48149871 regular 59.9MB 3 weeks ago 0 false
86569a54d5d4 regular 16.5MB 3 weeks ago 0 false
etc. with docker system df -v
but the only way I see to remove any is completely wiping all Docker data, including images, etc. which I don't want to do. Is there any other way to make Docker to reclaim the space? I can see those objects but I can find no way of deleting them...
P.S.1 This question is not about how to delete images and containers. I know how to delete them, unfortunately deleting either does nothing to the "Build Cache" contents which continues to occupy space.
P.S.2 This is especially important on MacOS because there Docker operates within one specific allocated volume, which this way gets exhausted very quickly and I start getting "out of disk space" errors when building. Since the builds are done repeatedly, keeping data from old builds is not useful for me, so finding a way to delete old build caches would be great.
Builds are cached by branch. If you want to manually clear the cache and trigger a new build you can do so by clicking on the Trigger build dropdown button and selecting the Clear cache and build option.
Remove all images All the Docker images on a system can be listed by adding -a to the docker images command. Once you're sure you want to delete them all, you can add the -q flag to pass the image ID to docker rmi : List: docker images -a.
When you use the Docker build command to build a Docker image, you can simply use the --no-cache option which will allow you to instruct daemon to not look for already existing image layers and simply force clean build of an image.
docker builder prune
Removes build cache. Docs: docker builder prune
docker builder prune --all
more details: https://docs.docker.com/engine/reference/commandline/builder_prune/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With