Docker私有仓库Registry V2 搭建(附带CA证书自签名)

#==>域名或主机名

signdomain=a.b.cn

#==>生成SSL证书

mkdir ~/certs
openssl req -nodes -subj "/C=CN/ST=ZheJiang/L=HangZhou/CN=$signdomain" -newkey rsa:4096 -keyout ~/$signdomain.key -out ~/$signdomain.csr
openssl x509 -req -days 3650 -in ~/$signdomain.csr -signkey ~/$signdomain.key -out ~/$signdomain.crt

#==>运行docker registry v2

docker run -d -p 5000:5000 --restart=always --name registry \
  -v ~/certs:/certs \
  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/$signdomain.crt \
  -e REGISTRY_HTTP_TLS_KEY=/certs/$signdomain.key \
  registry:2

#==>尝试 push 镜像

docker tag ubuntu a.b.cn:5000/ubuntu
docker push a.b.cn:5000/ubuntu

#==>出现如下错误:

The push refers to a repository [a.b.cn:5000/ubuntu] (len: 1)

unable to ping registry endpoint https://a.b.cn:5000/v0/

v2 ping attempt failed with error: Get https://a.b.cn:5000/v2/: x509: certificate signed by unknown authority

 v1 ping attempt failed with error: Get https://a.b.cn:5000/v1/_ping: x509: certificate signed by unknown authority

#==>错误是由于没有权威认证的自签名证书引起,在将crt复制docker Damon 的节点上如下目录(以当前节点示例,其它节点类似 scp 过去):

mkdir /etc/docker/certs.d/$signdomain:5000
cp ~/certs/$signdomain.crt /etc/docker/certs.d/$signdomain:5000/ca.crt

#==>验证 pull 和 push

docker pull a.b.cn:5000/ubuntu


你可能感兴趣的:(Docker私有仓库Registry V2 搭建(附带CA证书自签名))