ale*_*olk 10 environment-variables amazon-s3 docker docker-registry
有没有人尝试使用环境变量覆盖注册表中的配置选项,例如,如果必须使用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
Run Code Online (Sandbox Code Playgroud)
所以我尝试了这个命令,但是当我启动注册表时似乎没有任何效果:
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
Run Code Online (Sandbox Code Playgroud)
在日志中,我看到常规输出,好像它没有考虑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
Run Code Online (Sandbox Code Playgroud)
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#
Run Code Online (Sandbox Code Playgroud)
Dan*_*rza 18
从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
Run Code Online (Sandbox Code Playgroud)
请注意添加REGISTRY_STORAGE=s3环境变量.
他们在注册表文档中暗示了这一点:
注意:如果环境变量将映射值更改为字符串,例如使用REGISTRY_STORAGE = filesystem替换存储驱动程序类型,则将擦除所有子字段.因此,在环境中指定存储类型将删除与旧存储配置相关的所有参数.
小智 7
尝试添加-e REGISTRY_STORAGE=s3到您的docker run命令中.这会将默认filesystem配置覆盖为空.
详细信息:https://github.com/docker/distribution/blob/master/docs/configuration.md >覆盖配置选项>注意
| 归档时间: |
|
| 查看次数: |
5868 次 |
| 最近记录: |