在haproxy后面login私人dockerregistryv2
我正在尝试用HAProxybuild立一个新的Docker Registry(v2)。 对于Dockerregistry,我使用Docker集线器中的映像并使用docker run -d -p 5000:5000 -v /path/to/registry:/tmp/registry registry:2.0.1
。 这是我的HAProxyconfiguration的一个子集:
global chroot /var/lib/haproxy user haproxy group haproxy daemon tune.ssl.default-dh-param 2048 userlist auth_list group docker_registry users root user root password ***PASSWORD*** backend docker-registry server 127.0.0.1:5000_localhost 127.0.0.1:5000 cookie 127.0.0.1:5000_localhost frontend shared-frontend mode http bind *:80 bind *:443 ssl crt *** CERT FILES *** option accept-invalid-http-request acl domain_d.mydomain.com hdr(host) -i d.mydomain.com acl auth_docker_registry_root http_auth(auth_list) root redirect scheme https if !{ ssl_fc } domain_d.mydomain.com http-request auth realm Registry if !auth_docker_registry_root { ssl_fc } domain_d.mydomain.com use_backend docker-registry if domain_d.mydomain.com
需要注意的重要事项是我正在使用HAProxy进行SSL终止和HTTP身份validation而不是registry。
当我尝试login到新的registry时出现我的问题。 如果我运行docker login https://d.mydomain.com/v2/
然后input用户的root
和密码我收到以下错误信息:
Docker客户端:
FATA[0009] Error response from daemon: invalid registry endpoint https://d.mydomain.com/v2/: https://d.mydomain.com/v2/ does not appear to be a v2 registry endpoint. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry d.mydomain.com` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/d.mydomain.com/ca.crt
Docker守护进程:
ERRO[0057] Handler for POST /auth returned error: invalid registry endpoint https://d.mydomain.com/v2/: https://d.mydomain.com/v2/ does not appear to be a v2 registry endpoint. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry d.mydomain.com` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/d.mydomain.com/ca.crt ERRO[0057] HTTP Error: statusCode=500 invalid registry endpoint https://d.mydomain.com/v2/: https://d.mydomain.com/v2/ does not appear to be a v2 registry endpoint. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry d.mydomain.com` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/d.mydomain.com/ca.crt
所以我尝试join--insecure-registry d.mydomain.com
到:
-
/etc/default/docker
DOCKER_OPTS= -H unix:///var/run/docker.sock --insecure-registry d.mydomain.com
withDOCKER_OPTS= -H unix:///var/run/docker.sock --insecure-registry d.mydomain.com
- 使用
docker -d --insecure-registry d.mydomain.com
手动启动docker -d --insecure-registry d.mydomain.com
这些,或任何其他我find网上工作。 每次重新启动Docker并尝试再次login后,都会给我提供相同的错误消息。
我已经尝试了一些其他的事情:
- 在浏览器去
d.mydomain.com
结果在404 - 在浏览器中转到
d.mydomain.com/v2/
结果是:{}
- 在login命令中用所有这些replace
https://d.mydomain.com/v2/
,但没有成功-
http://d.mydomain.com/v2/
-
d.mydomain.com/v2/
-
http://d.mydomain.com/
-
d.mydomain.com/
-
使用HAProxy进行SSL终止和HTTPauthentication的这种设置在过去使用了registry的第一个版本和较老版本的docker。 那么Dockerregistryv2中有什么改变? 这是否仍然有效? 如果它没有改变,为什么不能再使用--insecure-registry
标志呢?
此外,我一直在努力使这个工作一段时间,所以我可能已经忘记了我所尝试的所有事情。 如果有什么可行的,让我知道,我会试一试。
谢谢,JamesStewy
编辑
这个编辑已被移到下面的答案
我有它的工作。 所以这里是我的新configuration:
haproxy.cfg
global chroot /var/lib/haproxy user haproxy group haproxy daemon tune.ssl.default-dh-param 2048 userlist auth_list group docker_registry users root user root password ***PASSWORD*** backend docker-registry server 127.0.0.1:5000_localhost 127.0.0.1:5000 cookie 127.0.0.1:5000_localhost backend docker-registry-auth errorfile 503 /path/to/registry_auth.http frontend shared-frontend mode http bind *:80 bind *:443 ssl crt *** CERT FILES *** option accept-invalid-http-request acl domain_d.mydomain.com hdr(host) -i d.mydomain.com redirect scheme https if !{ ssl_fc } domain_d.mydomain.com acl auth_docker_registry_root http_auth(auth_list) root use_backend docker-registry-auth if !auth_docker_registry_root { ssl_fc } domain_d.mydomain.com rsprep ^Location:\ http://(.*) Location:\ https://\1 use_backend docker-registry if domain_d.mydomain.com
registry_auth.http
HTTP/1.0 401 Unauthorized Cache-Control: no-cache Connection: close Content-Type: text/html Docker-Distribution-Api-Version: registry/2.0 WWW-Authenticate: Basic realm="Registry" <html><body><h1>401 Unauthorized</h1> You need a valid user and password to access this content. </body></html>
不同之处在于http-request auth
行已被replace为use_backend docker-registry-auth
。 后端docker-registry-auth
没有服务器,它总会给出503
错误。 但503错误文件已被更改为registry_auth.http
。 在registry_auth.http
,错误代码被重写为401
,头WWW-Authenticate
设置为Basic realm="Registry"
,提供基本的HAProxy 401错误页面,最重要的是, Docker-Distribution-Api-Version
是设置为registry/2.0
。
因此,这个hacky解决scheme的设置与旧的http-request auth
行完全相同,除了现在设置了自定义标头Docker-Distribution-Api-Version
。 这允许这个设置通过https://github.com/docker/docker/blob/v1.7.0/registry/endpoint.go的 line 236
开始的testing。
所以现在当我运行docker login d.mydomain.com
,login成功,我的凭据被添加到.docker/config.json
。
第二个问题是,即使通过login,我也无法推送到新的存储库。通过在frontend
添加rsprep
行来解决这个问题。 该行所做的是修改Location
标题(如果存在),将所有http://
为https://
。
我还发现这一点的文件供将来参考。
作为对前一个答案的一个小澄清:我不得不改变这一行:
WWW-Authenticate: Basic realm="Registry"
对此:
WWW-Authenticate: Basic realm="Registry realm"
然后一切正常…
顺便说一句,散列通过可以使用mkpasswd(部分的whois deb包)