buildx
buildx copied to clipboard
Add support for type=local cache prune
If you build with
docker buildx build
....
--cache-from=type=local,src=docker_cache
--cache-to=type=local,dest=docker_cache,mode=max
...
there shall be an easy way to prune unused non tagged images in docker_cache.
Could you please support this?
@materemias You can try using docker buildx prune. This command is available from docker buildx version 0.4.0 onwards
@Prabhav-Thali thanks for the suggestion, the problem is that cache-to awaits a custom destination which afaik docker prune doesn't cover
I would love to see some way of pruning a local cache destination as well .. is there any workarounds?
The only workaround I found was to delete files in the local cache directory.
I was using the local cache in a github action, and running into problems with the cache growing forever (see also https://github.com/docker/build-push-action/issues/252). I was able to keep the cache pruned by manually deleting layers with find
# say our cache is in `/tmp/docker_cache`
$ touch /tmp/docker_cache_start # record a timestamp
$ docker buildx build ... \
--cache-from=type=local,src=/tmp/docker_cache \
--cache-to=type=local,dest=/tmp/docker_cache,mode=max
# delete layers that were not accessed during the docker buildx build
$ find /tmp/docker_cache -type f -not -neweram /tmp/docker_cache_start -delete
Obviously you could use other find incantations to delete layers based on age or size per your needs.