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

公有Docker Registry的操作

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

[[email protected] ]# docker login --默认即https://hub.docker.com

Username : simpledockerhub

Password: *****

Login Succeeded

[[email protected] ]# docker pull hello-world

[[email protected] ]# docker tag hello-world simpledockerhub/hello-world

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

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

私有Docker Registry的搭建

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

[[email protected] ]#  docker run -d -p 5000:5000 registry:2

[[email protected] ]#  docker tag hello-world localhost:5000/hello-world

[[email protected] ]#  docker push localhost:5000/hello-world

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

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

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

Registry主机10.76.64.63做如下操作:

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

[[email protected] ]# mkdir centos1_certs

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

[[email protected] ~]# 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里对应上
。。。

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

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

3. 修改hosts文件

[[email protected] ~]#  vi /etc/hosts

10.76.64.63 centos1

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

[[email protected] ~]# 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. 重启服务

[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl restart docker.service

6. 启动registry V2

[[email protected] ~]# 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命令

[[email protected] ]#  docker tag hello-world centos1:5000/hello-world

[[email protected] ~]# 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配置

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

[[email protected] ~]# docker tag hello-world centos1:5000/hello-world:1.1
[[email protected] ~]# 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目录,然后执行:

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

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

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

现在可以测试push命令了:

[[email protected] ~]# docker tag hello-world centos1:5000/helloworld
[[email protected] ~]# 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. [[email protected] ~]#vi /etc/hosts

10.76.64.82 centosdocker

2. [[email protected] ~]# vi /lib/systemd/system/docker.service

....

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

3. [[email protected] ~]# vi  /etc/docker/daemon.json

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

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

7. [[email protected] system]# docker tag hello-world centosdocker:5000/hello-world

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

部署到客户机除了不需要[[email protected] 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.*.*"

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

时间: 2024-08-05 04:34:47

Docker Registry使用:公有Docker Registry使用、私有Docker Registry的搭建的相关文章

Docker私有仓库Registry的搭建验证

1. 关于Registry 官方的Docker hub是一个用于管理公共镜像的好地方,我们可以在上面找到我们想要的镜像,也可以把我们自己的镜像推送上去.但是,有时候,我们的使用场景需要我们拥有一个私有的镜像仓库用于管理我们自己的镜像.这个可以通过开源软件Registry来达成目的. Registry在github上有两份代码:老代码库和新代码库.老代码是采用python编写的,存在pull和push的性能问题,出到0.9.1版本之后就标志为deprecated,不再继续开发.从2.0版本开始就到

docker私有仓库registry部署

准备环境:两个装有Docker(版本1.12)的虚拟机虚拟机一:192.168.2.55 用户开发机虚拟机二:192.168.2.10 用作私有仓库 搭建私有仓库 首先在10机器上下载registry镜像 $ docker pull registry 下载完之后我们通过该镜像启动一个容器 $ sudo docker run -d --restart=always -p 5000:5000 -v /export/data/docker/registry:/tmp/registry registry

Docker容器学习梳理--私有仓库Registry使用

但有时候使用Docker Hub这样的公共仓库可能不方便,这种情况下用户可以使用registry创建一个本地仓库供私人使用,这点跟Maven的管理类似.使用私有仓库有许多优点: 1)节省网络带宽,针对于每个镜像不用每个人都去中央仓库上面去下载,只需要从私有仓库中下载即可: 2)提供镜像资源利用,针对于公司内部使用的镜像,推送到本地的私有仓库中,以供公司内部相关人员使用. 目前Docker Registry已经升级到了v2,最新版的Docker已不再支持v1.Registry v2使用Go语言编写

Docker私有仓库 Registry中的镜像管理

如何删除私有 registry 中的镜像? 首先,在默认情况下,docker registry 是不允许删除镜像的,需要在配置config.yml中启用:vim /etc/docker/registry/config.yml version: 0.1 log: fields: service: registry storage: delete: enable: true cache: blobdescriptor: inmemory filesystem: rootdirectory: /var

Docker私有仓库registry+nginx(https)

Docker仓库 仓库(Repository)是集中存放镜像的地方. 一个容易混淆的概念是注册服务器(Registry) .实际上注册服务器是管理仓库的具体服务器,每个服务器上可以有多个仓库,而每个仓库下面有多个镜像.从这方面来说,仓库可以被认为是一个具体的项目或目录.例如对于仓库地址 docker.sina.com.cn/centos:centos63 来说,docker.sina.com.cn 是注册服务器地址,centos 是仓库名,centos63 是仓库的 tag. Docker Hu

教你分分钟搞定Docker私有仓库Registry

一.什么是Docker私有仓库Registry 官方的Docker hub是一个用于管理公共镜像的好地方,我们可以在上面找到我们想要的镜像,也可以把我们自己的镜像推送上去.但是,有时候我们的服务器无法访问互联网,或者你不希望将自己的镜像放到公网当中,那么你就需要Docker Registry,它可以用来存储和管理自己的镜像. 二.安装Docker及Registry 安装Docker见之前博文: http://www.cnblogs.com/Javame/p/5492543.html 安装Regi

Docker 之 私有仓库registry

摘要: 1.拉去 registry镜像,例如在daocloud.io/registry这个私有镜像仓库 docker pull daocloud.io/registry 2.运行容器,挂在镜像内docker镜像仓库/var/lib/registry 至本地/root/my_docker_registry 1.拉去 registry镜像,例如在daocloud.io/registry这个私有镜像仓库 docker pull daocloud.io/registry 2.运行容器,挂在镜像内dock

创建私有Docker Registry的坑

1.创建私有docker registry: docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry --name registry registry:2 清理过期容器的shell脚本: #!/bin/bashdocker stop $(docker ps -a -q)docker rm $(docker ps -a -q) 2.创建docker registry,假如不使用默认的https格式,那么所有的客户端和服务端必须设

搭建私有Docker Registry

Docker的Docker Hub是一个公有的Registry, 从Docker Hub上可以找到很多的官方或个人构建的Docker Image, 通常, 这些image能满足开发.测试的需求.  但是如果想构建的image只在控制范围内共享, 而不是开放环境, 那就得搭建自己的私有Docker Registry. Docker官方实现了docker-registy, 根据官方的说明可以搭建自己的Docker Registry, 官方有两种方式搭建Docker Registry, 一种是按传统的