有没有人尝试使用环境变量来覆盖注册表中的配置选项,例如,如果您必须使用s3 bucket作为存储空间.我读了这个文件,它说(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
在日志中,我看到常规的输出,好像它不考虑env变量并尝试连接到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注册表容器,可以停靠码头利用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运行命令为我工作的完整命令是:
原文链接:https://www.f2er.com/docker/436379.htmldocker 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.