侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

详解Docker私有仓库最简便的搭建方法

Docker  /  管理员 发布于 7年前   200

Doker 在业界的应用越来越广泛,怎么用户管理好自己的镜像、容器等就是一个迫在眉睫的任务。

由于业务需要,我们需要在搭建一套自己的 Docker 私有镜像仓库,网上找了很多,都是说要 pull 一个 regisitry 镜像,然后通过这个镜像启动一个容器来运行仓库应用,我按照官网的说明 pull 了一个 registry ,但是启动的时候有报错,具体是什么就不细说了,反正是有错,于是开始研究别的方法,别说还真找到了一个,而且是我发现的最简便的办法,我不知道我是不是国内第一个发现的,但我应该是第一个写出来给大家参考的。

下面不废话,直接说方法:

  • 首先,你的系统要是 CentOS 7.0 以上,因为内核的要求,以及各种相关的库和软件的需要,以及 epel 的需要。
  • 直接安装 docker-registry 这个包。
  • 稍微修改一下配置,让你的私有仓库支持 http,因为从 docker1.3.2 开始,docker registry 默认都是使用 https 协议而不使用 http,甭管你从 docker hub 上找你需要的镜像,还是你自己打出来的 private registry。
  • 重启相关的 docker 服务。
  • 测试及使用。

下面就详细列一下每一步的步骤:

使用 CentOS 7.X 系统,添加 epel 源,并更新系统到最新版本,重启让新的内核生效。

#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo#yum clean all#yum makecache#yum update -y#reboot

安装 docker 相关的服务,其中 docker-registry 这个最重要,因为这就是私有仓库的服务,有了这个服务就不需要像网上一样去 pull 镜像,然后再起一个容器。

#yum install docker docker-registry -y

如果不需要开发相关的接口调用程序,这两个就够了,如果需要开发就直接安装所有的 docker 包,一共也没几个。但是最好把 docker-latest 和 docker-latest-logrotate 两个包卸载掉,因为这俩是 docker 客户端,版本是 1.12 跟 server 的版本 1.10 不是太匹配。

#yum install docker* -y#yum remove docker-latest* -y

把 docker 的两个服务设置为自动启动,并让其运行。

#systemctl enable docker#systemctl start docker#systemctl enable docker-registry#systemctl start docker-registry

查看一下本机监听的端口,是不是有5000这个端口了?5000端口就是默认的 docker-registry 监听端口,当然,这个你可以根据自己喜欢进行修改。

[root@01 /]# netstat -tnlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address   Foreign Address   State  PID/Program nametcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN  1109/sshdtcp  0  0 127.0.0.1:25   0.0.0.0:*    LISTEN  1384/mastertcp  0  0 0.0.0.0:5000   0.0.0.0:*    LISTEN  20437/pythontcp6  0  0 :::22     :::*     LISTEN  1109/sshdtcp6  0  0 ::1:25     :::*     LISTEN  1384/master

测试一下是不是能通过网络进行访问了?

[root@01 /]# curl "http://192.168.1.107:5000""\\"docker-registry server\\""[root@01 /]#[root@01 /]#

既然可以访问了,那就往这上面 push 一个镜像来测试一下吧。这个需要你首先 tag 一个镜像,然后才能 push 上去。以我目前的已经有的镜像为例。

[root@01 /]# docker tag cfba59e097ba 192.168.1.107:5000/test1[root@01 /]# docker imagesREPOSITORY     TAG     IMAGE ID   CREATED    SIZE192.168.1.107:5000/test1 latest    ac0b483c17fa  3 days ago   634.6 MBdocker.io/redmine   latest    cfba59e097ba  3 days ago   634.6 MBdocker.io/registry   latest    c9bd19d022f6  2 weeks ago   33.27 MB[root@01 /]#

现在 push 的话有报错,如下。

[root@01 /]# docker pull 192.168.1.107:5000/test1Using default tag: latestTrying to pull repository 192.168.1.107:5000/test1 ...unable to ping registry endpoint https://192.168.1.107:5000/v0/v2 ping attempt failed with error: Get https://192.168.1.107:5000/v2/: EOF v1 ping attempt failed with error: Get https://192.168.1.107:5000/v1/_ping: EOF[root@01 /]#

但是基本上一眼就能看出来,地址里都是 https,而我现在能访问的只是 http,所以,就需要解决启用 http 的问题,因为我的需求是在内网里搭建,外网无法访问,何必要加密,只会拖慢速度。接下来就是修改对应的配置文件,启用 http ,这个配置文件也是有说这个有说那个的,下面的才是正确的配置文件,亲测有效,如下。

[root@01 /]# vim /etc/sysconfig/docker

把下面这一行添加进去。

OPTIONS='--insecure-registry 192.168.1.107:5000'

重启 docker 服务。

[root@01 /]# systemctl restart docker docker-registry

再次 push,成功完成。

[root@01 system]# docker push 192.168.1.107:5000/test1The push refers to a repository [192.168.1.107:5000/test1]07c28c5d0371: Image successfully pushed6365a80ad26a: Image successfully pushedc5e7c0f1d017: Image successfully pushedb45f06d28f46: Image successfully pushed3f3c0394ba5a: Image successfully pushedddd6e2a8209e: Image successfully pushedf306cb9361f7: Image successfully pushed2d143a3783bc: Image successfully pushedf110684b8ae3: Image successfully pushedd7d24df90586: Image successfully pushede26addf75a78: Image successfully pushed82c666956815: Image successfully pushed9a2b1c643e93: Image successfully pushedeb9546f264dc: Image successfully pushedf96222d75c55: Image successfully pushedPushing tag for rev [cfba59e097ba] on {http://192.168.1.107:5000/v1/repositories/test1/tags/latest}[root@01 system]#

既然成功了,就往下 pull 一下试试,看看能不能让别的机器用,结果当然也是成功的,因为我已经 pull 过了,所以显示镜像已经存在,如下。

[root@01 /]# docker pull 192.168.1.107:5000/test1Using default tag: latestTrying to pull repository 192.168.1.107:5000/test1 ...Pulling repository 192.168.1.107:5000/test1cfba59e097ba: Already existsf96222d75c55: Already existsd17727727b61: Already exists92db66c8ffce: Already exists10a436a2f8fa: Already exists8b40995a66da: Already existsa2cba87d9ea4: Already exists5a187c7a57c4: Already existsd15f50d30606: Already exists4366383cdf86: Already existsc7cb938f30c3: Already existsf135d604f740: Already exists3f3d23c69aef: Already existse6adcc9c0e4b: Already exists53289b480679: Already existsStatus: Image is up to date for 192.168.1.107:5000/test1:latest192.168.1.107:5000/test1: this image was pulled from a legacy registry. Important: This registry version will not be supported in future versions of docker.[root@01 /]#

至此,简单的私有仓库已经搭建完毕,后续如果有需求要在公网上提供服务的话,加 SSL 证书,加用户名/密码等操作按部就班地去完成就行了。IT 技术更新很快,可能之前还没有这个服务,只是最近才有,所以,选了这一行就需要一辈子不断学习不断进步才能站在桥头迎风斩浪。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    在Centos7中安装Docker1.12的详细教程
    下一条:
    centos修改docker网络配置方法分享
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在docker环境中实现Laravel项目执行定时任务和消息队列流程步骤(0个评论)
    • 在MacBook下laravel项目多php版本docker开发环境配置方案(0个评论)
    • 在docker环境中部署docker部署elk架构流程步骤(1个评论)
    • docker compose跟Dockerfile的区别浅析(0个评论)
    • Ubuntu 22.04系统中安装podman流程步骤(1个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2017-11
    • 2020-06
    • 2021-05
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-11
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2024-03
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客