我的路由器后面有 QNAP NAS,公共 IP 为 1.2.3.4。我有 xxxx.yyyy.cz 证书。证书有效,我可以通过 HTTPS 访问我的 NAS。我在 NAS 上安装了 dockerregistry:2.7
。这是容器环境配置:
REGISTRY_HTTP_ADDR 0.0.0.0:5443
REGISTRY_HTTP_TLS_CERTIFICATE /certs/client.cert
REGISTRY_HTTP_TLS_KEY /certs/client.key
我设置了端口转发 5443 到 5443 TCP。在证书目录中有 3 个文件:
/certs # ls -al
total 24
drwxrwxrwx 2 root root 4096 Oct 20 17:02 .
drwxr-xr-x 1 root root 4096 Oct 20 17:01 ..
-rwxrwxrwx 1 root root 1688 Oct 20 16:42 ca.crt
-rwxrwxrwx 1 root root 2060 Oct 20 16:42 client.cert
-rwxrwxrwx 1 root root 1704 Oct 20 16:42 client.key
我能够使用 curl 或通过浏览器从注册表获得响应:
$ curl --cacert Downloads/certs/ca.crt https://xxxx.yyyy.cz:5443/v2/_catalog ; echo $?
{"repositories":[]}
0
所以我确定证书是正确的,注册表运行正常。当我看到容器日志时,我仍然收到以下消息:
2019/10/20 17:51:10 http: TLS handshake error from 1.2.3.4:58164: tls: first record does not look like a TLS handshake
2019/10/20 17:51:30 http: TLS handshake error from 1.2.3.4:58334: tls: first record does not look like a TLS handshake
2019/10/20 17:51:50 http: TLS handshake error from 1.2.3.4:58498: tls: first record does not look like a TLS handshake
2019/10/20 17:52:11 http: TLS handshake error from 1.2.3.4:58654: tls: first record does not look like a TLS handshake
2019/10/20 17:52:31 http: TLS handshake error from 1.2.3.4:58810: tls: first record does not look like a TLS handshake
2019/10/20 17:52:51 http: TLS handshake error from 1.2.3.4:58982: tls: first record does not look like a TLS handshake
2019/10/20 17:53:12 http: TLS handshake error from 1.2.3.4:59136: tls: first record does not look like a TLS handshake
当我尝试将某些内容推送到我的注册表时,我收到错误:
$ docker push xxxx.yyyy.cz:5443/myimage:latest
The push refers to repository [xxxx.yyyy.cz:5443/myimage]
Get https://xxxx.yyyy.cz:5443/v2/: x509: certificate signed by unknown authority
在码头工人日志中,我可以看到错误消息:
2019/10/20 18:43:28 http: TLS handshake error from 1.2.3.4:41632: remote error: tls: bad certificate
我使用了这个和这个说明,但它没有帮助。登录到容器后,我检查了我的证书文件 sha256,它们没问题。
- 如何在我的 docker 注册表上使用 TLS 以及为什么它不接受 我的证书?
- 为什么它不能通过 docker 命令工作?
我对client.cert
有问题。它还应包含ca.crt
,如使用中间证书一节中所述:
证书颁发者可能会为您提供中间证书。在这种情况下,您必须将证书与中间证书连接起来以形成证书捆绑包。您可以使用 cat 命令执行此操作:
cat domain.crt intermediate-certificates.pem > certs/domain.crt
您可以使用证书捆绑包,就像在上一示例中使用 domain.crt 文件一样。