Docker registry:2.0 覆盖配置选项

Docker registry:2.0 overriding configuration options

有没有人尝试过使用环境变量来覆盖注册表中的配置选项,例如,如果您必须使用 s3 存储桶作为存储。我阅读了文档,上面写着 (https://docs.docker.com/registry/configuration/):

Overriding configuration options
Environment variables may be used to override configuration parameters other than 
version. To override a configuration option, create an environment variable named 
REGISTRY_variable_ where variable is the name of the configuration option.

e.g

REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/tmp/registry/test

will set the storage root directory to /tmp/registry/test

所以我尝试了这个命令,但是当我启动注册表时它似乎没有任何效果:

docker run -it -v /var/log/docker-registry:/var/log -p 5000:5000 \
-e REGISTRY_STORAGE_S3_ACCESSKEY=****************** \
-e REGISTRY_STORAGE_S3_SECRETKEY=****************** \
-e REGISTRY_STORAGE_S3_BUCKET=itmcc-docker-registry-backend \
-e REGISTRY_STORAGE_S3_REGION=us-east-1 \
registry:2.0

在日志中我看到常规输出,好像它没有考虑环境变量并尝试连接到 S3:

INFO[0000] endpoint local-8082 disabled, skipping        environment=development instance.id=025c9fcd-2ec1-4d5f-82ec-d3246d54cdb5 service=registry version=v2.0.0
INFO[0000] endpoint local-8083 disabled, skipping        environment=development instance.id=025c9fcd-2ec1-4d5f-82ec-d3246d54cdb5 service=registry version=v2.0.0
INFO[0000] using inmemory layerinfo cache                environment=development instance.id=025c9fcd-2ec1-4d5f-82ec-d3246d54cdb5 service=registry version=v2.0.0
INFO[0000] listening on :5000                            environment=development instance.id=025c9fcd-2ec1-4d5f-82ec-d3246d54cdb5 service=registry version=v2.0.0
INFO[0000] Starting upload purge in 42m0s                environment=development instance.id=025c9fcd-2ec1-4d5f-82ec-d3246d54cdb5 service=registry version=v2.0.0
INFO[0000] debug server listening localhost:5001

PS:如果我在我的 ec2 上使用 IAM 角色,将访问和密钥传递给 docker 注册表容器似乎是多余的,可以 docker 使用 IAM还没用,有人试过吗?

编辑: 在我 运行 容器和 exec 命令查看 env:

的输出之后
root@0a349294f792:/go/src/github.com/docker/distribution# env
REGISTRY_STORAGE_S3_SECRETKEY=*************************
DISTRIBUTION_DIR=/go/src/github.com/docker/distribution
GOLANG_VERSION=1.4.2
HOSTNAME=0a349294f792
REGISTRY_STORAGE_S3_BUCKET=itmcc-docker-registry-backend
PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/go/src/github.com/docker/distribution
REGISTRY_STORAGE_S3_REGION=us-east-1
SHLVL=1
HOME=/root
GOPATH=/go/src/github.com/docker/distribution/Godeps/_workspace:/go
REGISTRY_STORAGE_S3_ACCESSKEY=*************************
_=/usr/bin/env
root@0a349294f792:/go/src/github.com/docker/distribution#

我在 docker run 命令中通过环境变量加载 accesskey 和 secretkey。但是,我在配置文件中指定了我的存储桶名称和区域,在寻找问题解决方案的过程中,您似乎必须在配置文件中指定区域和存储桶名称。每当我尝试在我的 docker run 命令中的环境变量中指定这些时,我都会收到错误消息并且容器无法启动。我建议通过配置文件加载此信息(并在您的 docker run 命令中删除这些标志),并像您一样通过环境变量指定您的 accesskey 和 secretkey。我花了一些时间在源代码中挖掘有关为什么这不能按照我们认为应该的方式工作的信息,但没有发现任何真正有用的信息。我认为它一定是 AWS S3 不喜欢的东西,但我并没有试图阐明这一点,因为它在上述配置中对我有用。祝你好运!

PS:关于您的 IAM 访问,there are some comments in the source 这可能有助于您了解预期的结果。

尝试将 -e REGISTRY_STORAGE=s3 添加到您的 docker run 命令中。 这将用空覆盖默认 filesystem 配置。

详细信息:https://github.com/docker/distribution/blob/master/docs/configuration.md > 覆盖配置选项 > 注意

docker run 命令对我有用的完整命令是:

docker run -d -p 5000:5000 \
-e "REGISTRY_STORAGE=s3" \
-e "REGISTRY_STORAGE_S3_REGION=us-east-1"\
-e "REGISTRY_STORAGE_S3_BUCKET=******"\ 
-e "REGISTRY_STORAGE_S3_ACCESSKEY=******"\ 
-e "REGISTRY_STORAGE_S3_SECRETKEY=******"\ 
registry:2

注意 REGISTRY_STORAGE=s3 环境变量的添加。

他们在 registry docs 中暗示了这一点:

Note: If an environment variable changes a map value into a string, such as replacing the storage driver type with REGISTRY_STORAGE=filesystem, then all sub-fields will be erased. As such, specifying the storage type in the environment will remove all parameters related to the old storage configuration.