buildx icon indicating copy to clipboard operation
buildx copied to clipboard

Add support for type=local cache prune

Open materemias opened this issue 5 years ago • 3 comments

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 avatar Jun 15 '20 23:06 materemias

@materemias You can try using docker buildx prune. This command is available from docker buildx version 0.4.0 onwards

prabhav-thali avatar Jun 19 '20 10:06 prabhav-thali

@Prabhav-Thali thanks for the suggestion, the problem is that cache-to awaits a custom destination which afaik docker prune doesn't cover

materemias avatar Jun 23 '20 06:06 materemias

I would love to see some way of pruning a local cache destination as well .. is there any workarounds?

piotrb avatar May 13 '21 00:05 piotrb

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.

ryepup avatar May 17 '23 15:05 ryepup