Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for type=local cache prune #310

Open
materemias opened this issue Jun 15, 2020 · 4 comments
Open

Add support for type=local cache prune #310

materemias opened this issue Jun 15, 2020 · 4 comments
Labels
area/cache kind/enhancement New feature or request

Comments

@materemias
Copy link

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?

@prabhav-thali
Copy link

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

@materemias
Copy link
Author

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

@tonistiigi tonistiigi added the kind/enhancement New feature or request label Aug 25, 2020
@tonistiigi tonistiigi changed the title Add support for local cache prune Add support for type=local cache prune Aug 25, 2020
@piotrb
Copy link

piotrb commented May 13, 2021

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

@ryepup
Copy link

ryepup commented May 17, 2023

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 docker/build-push-action#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cache kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants