2017-11-11 104 views
2

我想配置一個本地docker註冊表,其中包含我將在本地網絡中使用的自簽名證書。我遵循碼頭手冊[1,2]的指示,但仍遇到錯誤。使用自簽名證書配置本地註冊表

準確地說,我的問題在於。我在本地註冊表計算機上創建一個自簽名證書:

openssl req \         
    -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key \ 
    -x509 -days 365 -out certs/domain.crt \ 
    -subj "/C=US/ST=Oregon/L=Portland/O=Company Name/OU=Org/CN=openmpi-dockerregistry.local" 

我把這個證書到/etc/docker/certs.d/openmpi-dockerregistry:443/ca.crt上各個地方的機器。

然後我開始註冊表並在那裏推送一個圖像。由於我的網絡中沒有配置DNS,因此我只需輸入/etc/hosts即可。

接下來,我儘量拉在本地機器上的圖像,但此操作失敗:

$ docker run -it openmpi-dockerregistry.local:443/hello-world 
Unable to find image 'openmpi-dockerregistry.local:443/hello-world:latest' locally 
docker: Error response from daemon: Get https://openmpi-dockerregistry.local:443/v2/: x509: certificate is not valid for any names, but wanted to match openmpi-dockerregistry.local. 
See 'docker run --help'. 

我對消息非常可疑「X509:證書是無效的任何名字」,這聽起來是我沒有正確指定CN,但閱讀出具的對面(full output):

$ openssl x509 -text -noout -in certs/domain.crt 
.... 
    Signature Algorithm: sha256WithRSAEncryption 
     Issuer: C = US, ST = Oregon, L = Portland, O = Company Name, OU = Org, CN = openmpi-dockerregistry.local 
.... 

我試過另一種選擇是直接IP訪問寄存器。我遵循手冊[3]並將IP SAN添加到證書中。另外我還設置了CN = *。這樣生成的證書現在包含以下(full):

 X509v3 extensions: 
      X509v3 Subject Alternative Name: 
       IP Address:<ip address> 

但現在當我嘗試拉像我得到以下錯誤消息:

$ docker run -it <ip>:443/hello-world 
Unable to find image '<ip>:443/hello-world:latest' locally 
docker: Error response from daemon: Get https://<ip>:443/v2/: x509: cannot validate certificate for <ip> because it doesn't contain any IP SANs. 
See 'docker run --help' 

儘管文件/etc/docker/certs.d/<ip>:443/ca.crt包含IP地址。

你能幫我找到一種方法從本地註冊表中提取圖像嗎?

更新

如何啓動泊塢窗註冊表?

$ docker run -d \ 
    -v `pwd`/certs:/certs \ 
    -e REGISTRY_HTTP_ADDR=0.0.0.0:$REGISTRY_PORT \ 
    -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \ 
    -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \ 
    -p $REGISTRY_PORT:$REGISTRY_PORT \ 
    --restart=always \ 
    --name registry \ 
    registry:2 
  1. https://docs.docker.com/registry/insecure/#use-self-signed-certificates
  2. https://docs.docker.com/registry/deploying/#run-an-externally-accessible-registry
  3. https://bowerstudios.com/node/1007
+0

檢查註冊表容器中的日誌('docker logs --follow $ INSTANCENAME')。如果問題出現在證書中,您會立即看到。這將有助於查看註冊表「config.yml」。 – Stefano

+0

它說:'從:44428:遠程錯誤:tls:壞證書'TLS握手錯誤對於域名和IP地址訪問。 – mcsim

+0

你可以分享你如何啓動註冊表? – Stefano

回答

1

我認爲問題是,你沒有證書和密鑰複製在/etc/docker/certs.d/文件夾中。

該文件夾應該是這樣的:

/etc/docker/certs.d/ 
└── openmpi-dockerregistry.local:443 
    ├── client.cert 
    ├── client.key 
    └── ca.crt 

在我來說,我沒有ca.crt它工作得很好。

參考:https://docs.docker.com/engine/security/certificates/


我實現您的設置我的機器上,一切正常後,我在/etc/docker/certs.d複製domain.key和domain.crt(和他們改名)夾。唯一的區別是我使用openmpi-dockerregistry作爲域而不是openmpi-dockerregistry.local

+0

我確實在文件夾中錯過了client.cert和client.key。我應該使用ca.crt以某種方式生成它們嗎? – mcsim

+0

其實它們是你傳遞給註冊表的'domain.crt'和'domain.key'。爲了測試的目的,我在OSX上重複了相同的設置,故事很相似,但不是複製'/ etc/docker/certs.d /'中的文件,而是將它們複製到〜/ .docker/certs.d中/ openmpi-dockerregistry:443' – Stefano

+0

所以client.cert和ca.crt是同一個文件?正如我前面寫的 – mcsim