Is it possible to export that RUN --mount cache to a file that can be restored later?

Locally the Docker builds can be sped up using RUN –mount type=cache to cache dependency downloads. I was wondering if it is possible to export the current state of the cache mounts to a file that can be stored in the CI cache like the one in Azure DevOps.

Within the Dockerfile you can only control what is cached, and which RUN instruction should use cache.

You can configure BuildKit / buildx to use cache-to and cache-from and even leverage Azure Buckets:
https://docs.docker.com/reference/cli/docker/buildx/build/#cache-to
https://docs.docker.com/reference/cli/docker/buildx/build/#cache-from

General details:
https://docs.docker.com/build/cache/optimize/#use-an-external-cache

1 Like

yeah we don’t have azure buckets and the pipelines are very isolated (no AWS S3 buckets either). The closest I can do at the moment is push to the registry which is what I have done, but I am not sure about the “mechanics” of it. Does it get wiped on the next push if it is the same image etc.

So what I did was have push using the pattern:

  1. cache-<branch>

Then cache-from

  1. cache-master
  2. cache-<branch>