栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

搭建Docker镜像私服

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

搭建Docker镜像私服

搭建Docker镜像私服
      • Docker官方的registry
      • Nexus
      • 注意事项

需求,原理,需要达成的效果都和Maven私服类似,没啥好说的

Docker官方的registry

这玩意还是之前开始了解Docker时用过,要了解的移步其他文章

Nexus

其实就综合评分而言,Harbor更有优势;但作为Java程序员出身,早早就使用了Nexus作为Maven私服,对这款软件有种莫名的好感,再者,就日常使用而言,Nexus作为Docker私服也是完全足够的;所以个人选择了Nexus。
至于Harbor就搭建时略有区别,针对docker的配置都是大同小异的,读者可借鉴思路。
开始

  • 搭建Nexus环境
    这里使用Docker-compose搭建
    脚本

    version: "3.8"
     services:
       nexus:
         image: sonatype/nexus3:3.33.1
         container_name: nexus_3_33_1
         restart: always
         privileged: true
         ports:
         - '18081:8081'
         - '5000:5000'
         - '15000:15000'
         volumes:
         - 'nexus_data:/nexus-data'
     volumes:
       nexus_data: {}
    

    运行

    docker-compose up -d
    

    结果

  • 配置仓库

    宿主仓库




    代理仓库


    其余默认即可;
    同上再加入docker中央仓库(https://registry-1.docker.io)

仓库组
其实这几个仓库的概念和Maven私服非常相似



至此,Nexus服务端的仓库配置基本完成

  • 配置客户端
    打开Docker配置文件
    vim /etc/docker/daemon.json
    
    若没有配置文件,则新建,该配置文件为Json格式
    加入以下内容
    "insecure-registries":["192.168.0.114:15000","192.168.0.114:5000"]
    
    重新服务
    [root@kapana docker-compose]# systemctl daemon-reload
    [root@kapana docker-compose]# systemctl restart docker.service
    
    测试客户端
    分别登录两个仓库
      [root@origin ~]# docker login 192.168.0.114:15000
      Username: admin
      Password: 
      WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
      Configure a credential helper to remove this warning. See
      https://docs.docker.com/engine/reference/commandline/login/#credentials-store
      Login Succeeded
    
      [root@origin ~]# docker login 192.168.0.114:5000
      Username: admin
      Password: 
      WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
      Configure a credential helper to remove this warning. See
      https://docs.docker.com/engine/reference/commandline/login/#credentials-store
      
      Login Succeeded
    
  • 配置免密拉取镜像
    默认,Nexus要求用户必须先登录授权才能拉取镜像,但在某些场景下这是不合理的,为此需要配置部分仓库免密拉取
    1. 创建免密拉取角色
      原本想直接修改匿名角色,但是系统不让修改;直接新建一个角色

    2. 创建一个匿名拉取的用户
      同样的,这里原本是想直接修改匿名用户,直接追加新角色的,但实验了很多次,也翻了些文档还是没解决,所以直接新建一个匿名拉取的用户,将这个用户赋予原有的匿名角色和新建的角色

    3. 配置匿名访问

    4. 测试匿名拉取
      清除本地已授权信息

          [root@origin ~]# docker logout 192.168.0.114:5000
         	Removing login credentials for 192.168.0.114:5000
         	[root@origin ~]# docker logout 192.168.0.114:15000
         	Removing login credentials for 192.168.0.114:15000
      

      拉取镜像

      [root@origin ~]# docker pull 192.168.0.114:15000/hello-world
      Using default tag: latest
      latest: Pulling from hello-world
      2db29710123e: Pull complete 
      Digest: sha256:9ade9cc2e26189a19c2e8854b9c8f1e14829b51c55a630ee675a5a9540ef6ccf
      Status: Downloaded newer image for 192.168.0.114:15000/hello-world:latest
      192.168.0.114:15000/hello-world:latest
      


      至此,匿名拉取完成。

注意事项

使用Docker私服时,注意区分宿主仓库和组仓库;
组仓库:用于拉取镜像,会根据仓库优先级去拉取镜像
宿主仓库:主要用于推送本地镜像
所以拉取和推送的端口是不一样的

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/284166.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号