首页 > 其他 > 详细

Docker Registry使用:公有Docker Registry使用、私有Docker Registry的搭建

时间:2018-08-03 18:40:03      阅读:151      评论:0      收藏:0      [点我收藏+]

公有Docker Registry的操作

首先必须注册自己的dockerhub账号,假设为simpledockerhub

[root@localhost ]# docker login --默认即https://hub.docker.com

Username : simpledockerhub

Password: *****

Login Succeeded

[root@localhost ]# docker pull hello-world

[root@localhost ]# docker tag hello-world simpledockerhub/hello-world

[root@localhost ]#docker push simpledockerhub/hello-world     ------注意 /前面的名称必须是用户注册的用户名。

这样就把hello-world镜像上传到simpledockerhub用户下,使用docker pull命令就可以下载该镜像了

私有Docker Registry的搭建

1. 单机版:只能通过localhost操作(个人玩玩还行)

[root@localhost ]#  docker run -d -p 5000:5000 registry:2

[root@localhost ]#  docker tag hello-world localhost:5000/hello-world

[root@localhost ]#  docker push localhost:5000/hello-world

2.通过自签名证书方式联机访问(生产环境推荐使用该方案):

在主机上安装一个自签名的证书,并同时给需要访问寄存服务器的每个Docker 守护进程都安装一份。

Registry主机地址:10.76.64.63,  访问者地址:10.76.64.82

Registry主机10.76.64.63做如下操作:

1. 创建目录,存放证书文件:

[root@localhost ]# mkdir centos1_certs

2. 生成自签名证书,拷贝到 /etc/docker/certs.d/centos1:5000目录

[root@centos1 ~]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout centos1_certs/domain.key -x509 -days 365 -out centos1_certs/domain.crt
。。。
Common Name (eg, your name or your server‘s hostname) []:centos1    ---这个为主机名称,需要和/etc/hosts里对应上
。。。

[root@centos1 ~]# mkdir -p /etc/docker/certs.d/centos1:5000

[root@centos1 ~]# cp centos1_certs/domain.crt /etc/docker/certs.d/centos1:5000/domain.crt

3. 修改hosts文件

[root@centos1 ~]#  vi /etc/hosts

10.76.64.63 centos1

4. 修改docker代理服务器文件(如果原来没有设置可以跳过)

[root@centos1 ~]# vi /etc/systemd/system/docker.service.d/http-proxy.conf      --------该文件配置见:https://www.cnblogs.com/onetwothree/p/9371752.html

[Service]
Environment="NO_PROXY=127.0.0.1,localhost,centos1,10.76.*.*"

5. 重启服务

[root@centos1 ~]# systemctl daemon-reload
[root@centos1 ~]# systemctl restart docker.service

6. 启动registry V2

[root@centos1 ~]# docker run -d --rm -p 5000:5000 --name registry -v /root/centos1_certs:/certs -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key docker.io/registry:2

7. 测试push命令

[root@localhost ]#  docker tag hello-world centos1:5000/hello-world

[root@centos1 ~]# docker push centos1:5000/hello-world
The push refers to repository [centos1:5000/hello-world]
ee83fc5847cb: Pushed
latest: digest: sha256:aca41a608e5eb015f1ec6755f490f3be26b48010b178e78c00eac21ffbe246f1 size: 524

通过浏览器调用

技术分享图片

  到此为止可以通过主机名在本机访问registry了,如何在另外一台安装了docker环境的客户机访问registry呢?

8. 客户机10.76.64.82配置

直接访问:如下,报错是必然的

[root@centosdocker ~]# docker tag hello-world centos1:5000/hello-world:1.1
[root@centosdocker ~]# docker push centos1:5000/hello-world:1.1
The push refers to repository [centos1:5000/hello-world]
Get https://centos1:5000/v2/: Service Unavailable

解决步骤:

把centos1主机的domain.crt文件上传到客户机的centos1_certs目录,然后执行:

[root@centosdocker ~]# mkdir -p /etc/docker/certs.d/centos1:5000

[root@centosdocker ~]# cp centos1_certs/domain.crt /etc/docker/certs.d/centos1:5000/domain.crt

接下来执行上面的3、4、5步。

现在可以测试push命令了:

[root@centosdocker ~]# docker tag hello-world centos1:5000/helloworld
[root@centosdocker ~]# docker push centos1:5000/helloworld
The push refers to repository [centos1:5000/helloworld]
ee83fc5847cb: Mounted from hello-world
latest: digest: sha256:aca41a608e5eb015f1ec6755f490f3be26b48010b178e78c00eac21ffbe246f1 size: 524

 成功啦!

3.另外的方案:

对将要访问寄存服务器的所有Docker 守护进程加上-- insecure-registry ip或hostname:5000 参数,其中的地址和端口需要替换成你的服务器的信息,然后重新启动Docker 守护进程。

1. [root@centosdocker ~]#vi /etc/hosts

10.76.64.82 centosdocker

2. [root@centosdocker ~]# vi /lib/systemd/system/docker.service

....

OPTIONS=‘--selinux-enabled --insecure-registry centosdocker:5000‘      -----添加这一行
[Install]
WantedBy=multi-user.target

3. [root@centosdocker ~]# vi  /etc/docker/daemon.json

{"insecure-registries":["centosdocker:5000"] }

4. [root@centosdocker system]# systemctl daemon-reload
5. [root@centosdocker system]# systemctl restart docker.service
6. [root@centosdocker system]# docker run -d -p 5000:5000 registry:2

7. [root@centosdocker system]# docker tag hello-world centosdocker:5000/hello-world

8. [root@centosdocker system]# docker push centosdocker:5000/hello-world
The push refers to repository [centosdocker:5000/hello-world]
ee83fc5847cb: Pushed
latest: digest: sha256:aca41a608e5eb015f1ec6755f490f3be26b48010b178e78c00eac21ffbe246f1 size: 524

部署到客户机除了不需要[root@centosdocker system]# docker run -d -p 5000:5000 registry:2外,其他操作相同,有兴趣可以试一下,如果有代理的话,需要在docker的no_proxy配置项上添加上registry主机名,如:

[Service]
Environment="NO_PROXY=127.0.0.1,localhost,centos1,centosdocker,10.76.*.*"

 

Docker Registry使用:公有Docker Registry使用、私有Docker Registry的搭建

原文:https://www.cnblogs.com/onetwothree/p/9402455.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!