注册表缓存
目录
registry 缓存存储可以被视为 inline 缓存的扩展。与 inline 缓存不同,registry 缓存完全独立于镜像,这使得其使用更加灵活 - registry 支持的缓存可以完成 inline 缓存所能做的一切,甚至更多:
- 允许分离缓存和生成的图像工件,以便您可以在不包含缓存的情况下分发最终图像。
- 它可以在
max模式下高效地缓存多阶段构建,而不仅仅是最终阶段。 - 它与其他导出器一起工作以提供更大的灵活性,而不仅仅是
image导出器。
默认的docker驱动程序不支持此缓存存储后端。
要使用此功能,请使用不同的驱动程序创建一个新的构建器。有关更多信息,请参阅
构建驱动程序。
概要
与更简单的inline缓存不同,registry缓存支持多个配置参数:
$ docker buildx build --push -t <registry>/<image> \
--cache-to type=registry,ref=<registry>/<cache-image>[,parameters...] \
--cache-from type=registry,ref=<registry>/<cache-image> .
下表描述了可以传递给--cache-to和--cache-from的可用CSV参数。
| Name | Option | Type | Default | Description |
|---|---|---|---|---|
ref | cache-to,cache-from | String | Full name of the cache image to import. | |
mode | cache-to | min,max | min | Cache layers to export, see cache mode. |
oci-mediatypes | cache-to | true,false | true | Use OCI media types in exported manifests, see OCI 媒体类型. |
image-manifest | cache-to | true,false | false | When using OCI media types, generate an image manifest instead of an image index for the cache image, see OCI 媒体类型. |
compression | cache-to | gzip,estargz,zstd | gzip | Compression type, see 缓存压缩. |
compression-level | cache-to | 0..22 | Compression level, see cache compression. | |
force-compression | cache-to | true,false | false | Forcibly apply compression, see 缓存压缩. |
ignore-error | cache-to | Boolean | false | Ignore errors caused by failed cache exports. |
你可以为ref选择任何有效的值,只要它与你要推送镜像的目标位置不同。你可以选择不同的标签(例如foo/bar:latest和foo/bar:build-cache),不同的镜像名称(例如foo/bar和foo/bar-cache),甚至不同的仓库(例如docker.io/foo/bar和ghcr.io/foo/bar)。由你决定使用哪种策略来将你的镜像与缓存镜像分开。
如果--cache-from目标不存在,那么缓存导入步骤将会失败,但构建会继续。
进一步阅读
有关缓存的介绍,请参见 Docker 构建缓存。
有关registry缓存后端的更多信息,请参阅
BuildKit 自述文件。