Share feedback
Answers are generated based on the documentation.

Amazon S3 缓存

Availability: Experimental

s3 缓存存储会将你生成的构建缓存上传到 Amazon S3 文件存储服务 或其他兼容 S3 的服务,例如 MinIO

默认的 docker 驱动不支持这种缓存存储后端。要使用此功能,请使用不同的驱动创建一个新的 builder。更多信息请参阅 Build drivers

概要(Synopsis)

$ docker buildx build --push -t <user>/<image> \
  --cache-to type=s3,region=<region>,bucket=<bucket>,name=<cache-image>[,parameters...] \
  --cache-from type=s3,region=<region>,bucket=<bucket>,name=<cache-image> .

下表描述了你可以传递给 --cache-to--cache-from 的可用 CSV 参数。

Name Option Type Default Description
region cache-to,cache-from String 必填。地理位置。
bucket cache-to,cache-from String 必填。S3 存储桶的名称。
name cache-to,cache-from String buildkit 缓存镜像的名称。
endpoint_url cache-to,cache-from String S3 存储桶的端点。
prefix cache-to,cache-from String 添加到所有文件名前的前缀。
blobs_prefix cache-to,cache-from String blobs/ 添加到 blob 文件名前的前缀。
upload_parallelism cache-to Integer 4 并行上传层的数量。
touch_refresh cache-to Time 24h 更新未变化缓存层时间戳的间隔。
manifests_prefix cache-to,cache-from String manifests/ 添加到清单文件名前的前缀。
use_path_style cache-to,cache-from Boolean false true 时,在 URL 中使用 bucket 而非主机名。
access_key_id cache-to,cache-from String 参见 authentication
secret_access_key cache-to,cache-from String 参见 authentication
session_token cache-to,cache-from String 参见 authentication
mode cache-to min,max min 要导出的缓存层,参见 cache mode
ignore-error cache-to Boolean false 忽略由缓存导出失败引起的错误。

身份验证(Authentication)

Buildx 可以复用现有的 AWS 凭据(通过凭据文件或环境变量配置)来向 S3 推送和拉取缓存。或者,你可以使用 access_key_idsecret_access_keysession_token 属性直接在 CLI 上指定凭据。

有关使用环境变量和凭据文件进行身份验证的详细信息,请参阅 AWS Go SDK, Specifying Credentials

延伸阅读(Further reading)

有关缓存的入门介绍,请参阅 Docker 构建缓存

有关 s3 缓存后端的更多信息,请参阅 BuildKit README