Build cache import and export
BuildKit keeps internal cache so repeated builds may reuse prior work. External cache exporters make selected cached build data available beyond one builder. A cache is an optimization, not a release artifact or proof of correctness. Select a backend based on persistence, trust, size and driver support.
Worked example
Use this worksheet offline. Names and values are fictional; no live builder, credentials, Docker daemon or external requests are needed. Commands are illustrations, not observed results. Before separately authorized verification, identify the effective Docker endpoint, client credential configuration, builder and registry destination as applicable. Never disclose credential files or private context details.
Illustrative only; approved isolated lab requiredFirst build: --cache-to type=local,dest=./bm-cache-new,mode=maxLater build: --cache-from type=local,src=./bm-cache-newImage output: choose independentlyNo real cache or image exported.Local cache uses a directory; registry cache uses a separate registry reference; inline cache accompanies the image output. --cache-to exports while --cache-from imports. Where supported, mode=max includes more intermediate build cache than mode=min, which may help multi-stage rebuilds at storage cost. Backend availability depends on the driver and image store. Keep trusted cache writers separate from untrusted builds and do not place secrets in layers. Use a fresh lab-owned cache path and record cache size and build time only if measured. Docker documents local and registry cache support for the default Docker driver with the containerd image store enabled. Compare cold and warm runs with identical inputs, target, builder, exporter and measurement boundary. No measurement means no speedup claim.
Common mistake
A cache hit does not prove dependencies are current, reproducible or free of vulnerabilities.
Manual practice
Choose cache import and export flags for two offline build plans and list the evidence needed to compare cold and warm builds.
Worksheet: lab-fixtures/docker-buildx-multi-platform/06-cache-exporters/scenario.txt.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Build cache import and export — Knowledge check
Reason about multi-platform build reasoning.
Which flag exports cache?
What does mode=max generally include where supported?
Does a cache hit prove a release is correct?