Home Explore Blog Models CI



docker

2nd chunk of `content/manuals/build/cache/backends/_index.md`
42bbb5b2714ea47eb39936e08f703deec81e7985228b464b000000010000099b
Example `buildx` command using the `registry` backend, using import and export
cache:

```console
$ docker buildx build --push -t <registry>/<image> \
  --cache-to type=registry,ref=<registry>/<cache-image>[,parameters...] \
  --cache-from type=registry,ref=<registry>/<cache-image>[,parameters...] .
```

> [!WARNING]
>
> As a general rule, each cache writes to some location. No location can be
> written to twice, without overwriting the previously cached data. If you want
> to maintain multiple scoped caches (for example, a cache per Git branch), then
> ensure that you use different locations for exported cache.

## Multiple caches

BuildKit supports multiple cache exporters, allowing you to push cache to more 
than one destination. You can also import from as many remote caches as you'd 
like. For example, a common pattern is to use the cache of both the current 
branch and the main branch. The following example shows importing cache from 
multiple locations using the registry cache backend:

```console
$ docker buildx build --push -t <registry>/<image> \
  --cache-to type=registry,ref=<registry>/<cache-image>:<branch> \
  --cache-from type=registry,ref=<registry>/<cache-image>:<branch> \
  --cache-from type=registry,ref=<registry>/<cache-image>:main .
```

## Configuration options

This section describes some configuration options available when generating
cache exports. The options described here are common for at least two or more
backend types. Additionally, the different backend types support specific
parameters as well. See the detailed page about each backend type for more
information about which configuration parameters apply.

The common parameters described here are:

- [Cache mode](#cache-mode)
- [Cache compression](#cache-compression)
- [OCI media type](#oci-media-types)

### Cache mode

When generating a cache output, the `--cache-to` argument accepts a `mode`
option for defining which layers to include in the exported cache. This is
supported by all cache backends except for the `inline` cache.

Mode can be set to either of two options: `mode=min` or `mode=max`. For example,
to build the cache with `mode=max` with the registry backend:

```console
$ docker buildx build --push -t <registry>/<image> \
  --cache-to type=registry,ref=<registry>/<cache-image>,mode=max \
  --cache-from type=registry,ref=<registry>/<cache-image> .
```

This option is only set when exporting a cache, using `--cache-to`. When

Title: Multiple Caches and Configuration Options in Buildx
Summary
BuildKit supports multiple cache exporters and importers. A common pattern is to use caches from multiple branches. When generating cache exports, the `--cache-to` argument can be configured with options for cache mode (`min` or `max`), compression, and OCI media types. Cache mode determines which layers to include in the exported cache, and is set only when exporting a cache using `--cache-to`.