Docker | Buildkit Use Cache From
Question
I’ve recently updated our CI to use buildkit for building docker images. But I noticed that docker build command with –cache-from buildkit image is not reusing cache.
Answer
We need to provide --build-arg BUILDKIT_INLINE_CACHE=1 for docker build command so that cache metadata will written into image
From docs
In addition to local build cache, the builder can reuse the cache generated from previous builds with the –cache-from flag pointing to an image in the registry.
To use an image as a cache source, cache metadata needs to be written into the image on creation. This can be done by setting –build-arg BUILDKIT_INLINE_CACHE=1 when building the image. After that, the built image can be used as a cache source for subsequent builds.