Share feedback
Answers are generated based on the documentation.

Local cache

The local cache store is a simple cache option that stores your cache as files in a directory on your filesystem, using an OCI image layout for the underlying directory structure. Local cache is a good choice if you're just testing, or if you want the flexibility to self-manage a shared storage solution.

Synopsis

$ docker buildx build --push -t <registry>/<image> \
  --cache-to type=local,dest=path/to/local/dir[,parameters...] \
  --cache-from type=local,src=path/to/local/dir .

The following table describes the available CSV parameters that you can pass to --cache-to and --cache-from.

NameOptionTypeDefaultDescription
srccache-fromStringPath of the local directory where cache gets imported from.
digestcache-fromStringDigest of manifest to import, see cache versioning.
tagcache-to,cache-fromStringlatestTag of the cache manifest, see cache versioning.
destcache-toStringPath of the local directory where cache gets exported to.
modecache-tomin,maxminCache layers to export, see cache mode.
oci-mediatypescache-totrue,falsetrueUse OCI media types in exported manifests, see OCI media types.
image-manifestcache-totrue,falsetrueWhen using OCI media types, generate an image manifest instead of an image index for the cache image, see OCI media types.
compressioncache-togzip,estargz,zstdgzipCompression type, see cache compression.
compression-levelcache-to0..22Compression level, see cache compression.
force-compressioncache-totrue,falsefalseForcibly apply compression, see cache compression.
ignore-errorcache-toBooleanfalseIgnore errors caused by failed cache exports.
resetcache-totrue,falsefalseDelete blobs that no tag references, see cache versioning.

If the src cache doesn't exist, then the cache import step will fail, but the build continues.

Cache versioning

A local cache directory uses an OCI image layout. Its index.json file associates tags with cache manifests, while the blobs directory stores the manifest and cache data.

By default, BuildKit exports and imports the cache tagged latest. Use different tags to keep multiple caches in the same directory:

$ docker buildx build --cache-to type=local,dest=path/to/local/dir,tag=v1 .
$ docker buildx build --cache-to type=local,dest=path/to/local/dir,tag=v2 .

Exporting another cache with the same tag updates that tag to reference the new manifest. Manifests referenced by other tags remain unchanged.

Import a cache by specifying its tag:

$ docker buildx build --cache-from type=local,src=path/to/local/dir,tag=v1 .

A digest identifies an exact cache manifest. BuildKit reports the digest of each exported manifest in the build output. Use digest instead of tag when you need a specific manifest:

$ docker buildx build \
  --cache-from type=local,src=path/to/local/dir,digest=sha256:<DIGEST> .

If you specify both digest and tag, BuildKit uses digest.

By default, updating a tag doesn't delete the blobs used by its previous manifest. The previous manifest remains available by digest, so the local cache directory grows over time.

Buildx version 0.35.0 and later supports reset=true on export, which deletes blobs that no tag references:

$ docker buildx build --cache-to type=local,dest=path/to/local/dir,reset=true .

Blobs that other tags reference are kept. Manifests that no tag references are deleted, so you can no longer import them by digest.

Further reading

For an introduction to caching see Docker build cache.

For more information on the local cache backend, see the BuildKit README.