centos7构建https访问的docker私有仓库
Posted Neo_Gamer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7构建https访问的docker私有仓库相关的知识,希望对你有一定的参考价值。
测试在局域网机器上测试的,IP为192.168.22.65,以下内容均可替换成自己的机器IP。
测试docker-ce版本:18.09.3-rc1
-
安装docker环境,并拉取仓库镜像registry
①yum install docker-ce
②docker pull registry:latest
-
利用openssl库生成认证证书
①mkdir -p ~/certs
②编辑/etc/pki/tls/openssl.cnf文件,在[v3_ca]下方添加:
subjectAltName = IP:192.168.22.65
③openssl req -newkey rsa:4096 -nodes -sha256 -keyout ~/certs/192.168.22.65.key -x509 -days 365 -out ~/certs/192.168.22.65.crt
④在生成证书过程中填写Common name时,应输入ip地址或域名
⑤若第②步和第④步没有按照要求操作,则pull或push时可能会报错如:x509: cannot validate certificate for because it doesn’t contain any IP SANs -
将crt证书复制到docker
①mkdir /etc/docker/certs.d/192.168.22.65:5000
②cp ~/certs/192.168.22.65.crt /etc/docker/certs.d/192.168.22.65:5000/ca.crt
-
将crt证书复制到本机系统证书管理文件中
①cat ~/certs/192.168.22.65.crt >> /etc/pki/tls/certs/ca-bundle.crt
②若没有此步骤,可能在pull或push时会报错如:Get https:///v2/: x509: certificate signed by unknown authority -
重启docker
①systemctl daemon-reload && systemctl restart docker
-
添加http basic authentication
①docker run --entrypoint htpasswd registry:latest -Bbn username password > /opt/registry-var/auth/htpasswd
②命令行中username和password分别是登录registry的用户名和密码 -
运行registry
①docker run -d -p 5000:5000 --restart=always --name registry -v /opt/registry-var/auth/:/auth/ -v /opt/registry-var/:/var/lib/registry/ -v ~/certs:/certs -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" -e "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/192.168.22.65.crt" -e "REGISTRY_HTTP_TLS_KEY=/certs/192.168.22.65.key" registry:latest
-
查看已运行的registry容器
①docker container ls
-
登录registry
①docker login 192.168.22.65:5000
-
pull或push镜像
-
用idea连接时填写https://192.168.22.65:5000,并填写用户名和密码。
以上是关于centos7构建https访问的docker私有仓库的主要内容,如果未能解决你的问题,请参考以下文章