@@ -489,6 +489,46 @@ FROM alpine AS production-env
489489$ docker build -t mybuildimage --target build-env .
490490```
491491
492+ ### Specifying external cache sources
493+
494+ In addition to local build cache, the builder can reuse the cache generated from
495+ previous builds with the ` --cache-from ` flag pointing to an image in the registry.
496+
497+ To use an image as a cache source, cache metadata needs to be written into the
498+ image on creation. This can be done by setting ` --build-arg BUILDKIT_INLINE_CACHE=1 `
499+ when building the image. After that, the built image can be used as a cache source
500+ for subsequent builds.
501+
502+ Upon importing the cache, the builder will only pull the JSON metadata from the
503+ registry and determine possible cache hits based on that information. If there
504+ is a cache hit, the matched layers are pulled into the local environment.
505+
506+ In addition to images, the cache can also be pulled from special cache manifests
507+ generated by [ ` buildx ` ] ( https://github.com/docker/buildx ) or the BuildKit CLI
508+ (` buildctl ` ). These manifests (when built with the ` type=registry ` and ` mode=max `
509+ options) allow pulling layer data for intermediate stages in multi-stage builds.
510+
511+ The following example builds an image with inline-cache metadata and pushes it
512+ to a registry, then uses the image as a cache source on another machine:
513+
514+ ``` bash
515+ $ docker build -t myname/myapp --build-arg BUILDKIT_INLINE_CACHE=1 .
516+ $ docker push myname/myapp
517+ ```
518+
519+ After pushing the image, the image is used as cache source on another machine.
520+ BuildKit automatically pulls the image from the registry if needed.
521+
522+ ``` bash
523+ # on another machine
524+ $ docker build --cache-from myname/myapp .
525+ ```
526+
527+ > ** Note** : This feature requires the BuildKit backend. You can either
528+ > [ enable BuildKit] ( ../builder.md#buildkit ) or use the [ buildx] ( https://github.com/docker/buildx )
529+ > plugin. The previous builder has limited support for reusing cache from
530+ > pre-pulled images.
531+
492532### Squash an image's layers (--squash) (experimental)
493533
494534#### Overview
0 commit comments