为什么推送私人,安全的dockerregistry失败?

我想在自愈的AWS ECS群集上运行私有的,安全的,已authentication的dockerregistry。 群集设置完成并正常工作,但我努力获取registry:latest运行。 问题是,每次我推送一个图像,推动blob失败,并进入一个重试周期,除非我得到一个超时。

为了确保我的ECS设置不是阻塞器,我尝试使用Docker4Mac 1.12.0-a在本地设置一切。

首先,非常基本的设置工作。 我创build了我自己的registry映像版本,在那里我把我的TLS证书包和密钥以及必要的htpasswd文件直接放到映像中。 [我知道,这是不安全的,我只是做testing的目的]。 所以这里是我的Dockerfile

 FROM registry:latest COPY htpasswd /etc/docker COPY server_bundle.pem /etc/docker COPY server_key.pem /etc/docker 

server_bundle.pem为我的域mydomain.com (CN = * server_bundle.pem有一个通配符证书作为第一个证书,其次是中间CA证书,所以客户端应该很高兴。 我的htpasswd文件是使用推荐的方法创build的:

 docker run --entrypoint htpasswd registry:2 -Bbn heyitsme mysupersecurepassword > htpasswd 

我build立我的形象:

 docker build -t heyitsme/registry . 

之后我运行一个非常基本的W / O TLS和authentication版本:

 docker run --restart=always -p 5000:5000 heyitsme/registry 

我实际上可以拉,标记和重新推送一个图像:

 docker pull alpine docker tag alpine localhost:5000/alpine docker push localhost:5000/alpine 

这工作。 接下来,我通过环境variables进行TLS和基本身份validation工作:

 docker run -h registry.mydomain.com --name registry --restart=always -p 5000:5000 \ -e REGISTRY_HTTP_HOST=http://registry.mydomain.com:5000 \ -e REGISTRY_HTTP_TLS_CERTIFICATE=/etc/docker/server_bundle.pem \ -e REGISTRY_HTTP_TLS_KEY=/etc/docker/server_key.pem \ -e REGISTRY_AUTH=htpasswd \ -e REGISTRY_AUTH_HTPASSWD_REALM=Registry-Realm \ -e REGISTRY_AUTH_HTPASSWD_PATH=/etc/docker/htpasswd heyitsme/registry 

暂时我在/etc/hosts创build一个条目,其中说:

 127.0.0.1 registry.mydomain.com 

然后我login:

 docker login registry.mydomain.com:5000 Username: heyitsme Password: *********** Login Succeeded 

所以现在,让我们在这里标记和推送图像:

 docker tag alpine registry.mydomain.com:5000/alpine docker push registry.mydomain.com:5000/alpine The push refers to a repository [registry.mydomain.com:5000/alpine] 4fe15f8d0ae6: Retrying in 4 seconds 

会发生什么,docker客户端试图推碎片并失败。 然后它重试并再次失败,直到我超时。 接下来检查V2 API是否正常工作:

 curl -i -XGET https://registry.mydomain.com:5000/v2/ HTTP/1.1 401 Unauthorized Content-Type: application/json; charset=utf-8 Docker-Distribution-Api-Version: registry/2.0 Www-Authenticate: Basic realm="Registry-Realm" X-Content-Type-Options: nosniff Date: Thu, 15 Sep 2016 10:06:04 GMT Content-Length: 87 {"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":null}]} 

好的,如预期的那样。 所以我们下一次validation:

 curl -i -XGET https://heyitsme:mysupersecretpassword@registry.mydomain.com:5000/v2/ HTTP/1.1 200 OK Content-Length: 2 Content-Type: application/json; charset=utf-8 Docker-Distribution-Api-Version: registry/2.0 X-Content-Type-Options: nosniff Date: Thu, 15 Sep 2016 10:06:16 GMT {}% 

作品。 但推动仍然失败。

日志说:

 time="2016-09-15T10:24:34Z" level=warning msg="error authorizing context: basic authentication challenge for realm \"Registry-Realm\": invalid authorization credential" go.version=go1.6.3 http.request.host="registry.mydomain.com:5000" http.request.id=6d2ec080-6824-4bf7-aac2-5af31db44877 http.request.method=GET http.request.remoteaddr="172.17.0.1:40878" http.request.uri="/v2/" http.request.useragent="docker/1.12.0 go/go1.6.3 git-commit/8eab29e kernel/4.4.15-moby os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.0 \\(darwin\\))" instance.id=be3a8877-de64-4574-b47a-70ab036e7b79 version=v2.5.1 172.17.0.1 - - [15/Sep/2016:10:24:34 +0000] "GET /v2/ HTTP/1.1" 401 87 "" "docker/1.12.0 go/go1.6.3 git-commit/8eab29e kernel/4.4.15-moby os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.0 \\(darwin\\))" time="2016-09-15T10:24:34Z" level=info msg="response completed" go.version=go1.6.3 http.request.host="registry.mydomain.com:5000" http.request.id=8f81b455-d592-431d-b67d-0bc34155ddbf http.request.method=POST http.request.remoteaddr="172.17.0.1:40882" http.request.uri="/v2/alpine/blobs/uploads/" http.request.useragent="docker/1.12.0 go/go1.6.3 git-commit/8eab29e kernel/4.4.15-moby os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.0 \\(darwin\\))" http.response.duration=30.515131ms http.response.status=202 http.response.written=0 instance.id=be3a8877-de64-4574-b47a-70ab036e7b79 version=v2.5.1 172.17.0.1 - - [15/Sep/2016:10:24:34 +0000] "POST /v2/alpine/blobs/uploads/ HTTP/1.1" 202 0 "" "docker/1.12.0 go/go1.6.3 git-commit/8eab29e kernel/4.4.15-moby os/linux arch/amd64 UpstreamClient(Docker-Client/1.12.0 \\(darwin\\))" 2016/09/15 10:24:34 http: TLS handshake error from 172.17.0.1:40886: tls: first record does not look like a TLS handshake 

我还testing了原始registry映像的不同版本,特别是2以上的几个版本。 所有产生相同的错误。 如果有人可以帮我解决这个问题,那就太棒了。

解决了:

 -e REGISTRY_HTTP_HOST=https://registry.mydomain.com:5000 \ 

因为环境variables做了勾号。 只是之前使用http而不是https使连接失败。