Reusing the cache from a `RUN –mount=type=cache` docker build

I’m using the new experimental docker buildkit syntax to do a multistage build, as so:

Dockerfile:

RUN --mount=type=cache,target=/home/build/.build-cache,gid=1000,uid=1001 ./build

bash:

DOCKER_BUILDKIT=1 docker build .

Works great locally. On CI I get a new docker environment every time, so no caching.

I can export and import files into the env, but I don’t know where the cache is located. Any ideas?

Or should I be exporting/importing the cache via some docker command? I’ve read https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources and https://github.com/moby/buildkit#export-cache but it’s not clear to me which is buildkit specific, which docker specific or if either really applies to this cache mounted into the Dockerfile RUN command.

Source: StackOverflow