Amazon S3 缓存

受限

这是一个实验性功能。接口和行为不稳定,可能在未来的版本中发生变化。

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

默认的docker驱动程序不支持此缓存存储后端。 要使用此功能,请使用不同的驱动程序创建一个新的构建器。有关更多信息,请参阅 构建驱动程序

概要

$ 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参数。

NameOptionTypeDefaultDescription
regioncache-to,cache-fromStringRequired. Geographic location.
bucketcache-to,cache-fromStringRequired. Name of the S3 bucket.
namecache-to,cache-fromStringName of the cache image.
endpoint_urlcache-to,cache-fromStringEndpoint of the S3 bucket.
blobs_prefixcache-to,cache-fromStringPrefix to prepend to blob filenames.
upload_parallelismcache-toInteger4Number of parallel layer uploads.
touch_refreshcache-toTime24hInterval for updating the timestamp of unchanged cache layers.
manifests_prefixcache-to,cache-fromStringPrefix to prepend on manifest filenames.
use_path_stylecache-to,cache-fromBooleanfalseWhen true, uses bucket in the URL instead of hostname.
access_key_idcache-to,cache-fromStringSee authentication.
secret_access_keycache-to,cache-fromStringSee authentication.
session_tokencache-to,cache-fromStringSee authentication.
modecache-tomin,maxminCache layers to export, see cache mode.
ignore-errorcache-toBooleanfalseIgnore errors caused by failed cache exports.

认证

Buildx 可以重用现有的 AWS 凭据,这些凭据可以通过凭据文件或环境变量进行配置,用于将缓存推送到 S3 或从 S3 拉取缓存。或者,您可以使用 access_key_idsecret_access_keysession_token 属性直接在 CLI 上指定凭据。

请参考 AWS Go SDK, 指定凭证 了解关于使用环境变量和凭证文件进行身份验证的详细信息。

进一步阅读

有关缓存的介绍,请参见 Docker 构建缓存

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