• 【云原生-Docker篇】之 Docker Registry的搭建与使用


    一、Registry私仓介绍

    企业里面进行CICD的时候,需要将待发布的应用打成镜像推送到镜像仓库进行持续部署,此时肯定不方便推送到公有的镜像仓库,那么就需要自行搭建私有仓库了。

    好在Docker官方有Registry私有仓库的镜像,使得我们很方便就能基于容器搭建属于自己的镜像仓库。

    二、搭建过程

    # 拉取最新版本的镜像
    docker pull registry:latest
    
    # 启动registry容器
    docker run -d -p 5000:5000 --restart=always --name myRegistry registry:latest
    
    # 挂载数据卷启动registry容器
    # -v /mydata/docker-volume/registry/config/config.yml:/etc/docker/registry/config.yml  挂载数据卷,指定registry的配置文件,注意宿主机对应目录下要事先已经准备好了有内容的config.yml,否则会启动报错
    
    # -v /mydata/docker-volume/registry/image:/var/lib/registry registry:latest  挂载数据卷,指定私仓镜像的存放位置
    docker run -d -p 5000:5000 --restart=always --name myRegistry -v /mydata/docker-volume/registry/config/config.yml:/etc/docker/registry/config.yml -v /mydata/docker-volume/registry/image:/var/lib/registry registry:latest
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    下面给一个默认config.yml的配置内容:

    # 自定义yml配置文件
    version: 0.1
    log:
      fields:
        service: registry
    storage:
      cache:
        blobdescriptor: inmemory
      filesystem:
        rootdirectory: /var/lib/registry
    http:
      addr: :5000
      headers:
        X-Content-Type-Options: [nosniff]
    health:
      storagedriver:
        enabled: true
        interval: 10s
        threshold: 3
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    三、使用仓库

    原则上,所有能访问到镜像仓库所在宿主机的请求都能使用该Registry,只要在镜像名称前加上具体的服务器地址即可。

    • 上传本地镜像到私有仓库
    docker tag hello-world:latest localhost:5000/hello-world:latest
    docker push localhost:5000/hello-world:latest
    # 执行结果如下
    The push refers to repository [localhost:5000/hello-world]
    e07ee1baac5f: Pushed
    latest: digest: sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4 size: 525
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    我们可以在挂载的镜像数据卷/mydata/docker-volume/registry/image中看到,此时已经有存储镜像信息了,从而验证了确实Push成功。

    • 从私有仓库下载镜像到本地
    docker pull localhost:5000/hello-world:latest
    #执行结果如下
    latest: Pulling from hello-world
    2db29710123e: Pull complete
    Digest: sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4
    Status: Downloaded newer image for localhost:5000/hello-world:latest
    localhost:5000/hello-world:latest
    
    docker tag localhost:5000/hello-world:latest hello-world:latest
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    四、配置仓库

    如上已经提供了一个默认版本的仓库配置文件,其实仓库还可以进行如下项目的配置,但是目前自己还用不到,所以先做个记录,有时间再详细研究。

    • 版本号,这个没啥好说的,目前都是:
    version: 0.1
    
    • 1
    • 日志配置
    log: 
        # 级别选择debug,info,warn,error
        level: debug
        # 日志输出格式,可选text,json,logstash
        formatter: text
        # 增加到日志中的键值对,用于过滤日志
        fields:
            service: registry
            enviroment: staging
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • hooks,当仓库发生异常时通过邮件发送时的参数;

    • 存储选项,可以配置镜像存储引擎,有本地文件系统、各大服务的云存储服务等;

    • 认证选项,可选silly、token、htpassword等;

    • HTTP选项

    • 通知选项,有事件发生的时候需要通知的系统;

    • redis选项,用来缓存文件快;

    • 健康监控选项,配置对服务进行检测判断系统的状态;

    • 代理选项,配置当前registry作为一个Pull代理,从远端官方仓库拉取Docker镜像;

    • 验证选项,限定指定地址才可以Push镜像;

  • 相关阅读:
    通俗理解ABP中的模块Module
    kube-scheduler framework
    正点原子嵌入式linux驱动开发——Linux内核移植
    【Redis】几款redis可视化工具(推荐Another Redis Desktop Manager)
    已解决:Ubuntu系统开启电脑一直出现Boot Menu
    Kafka3.0.0版本——消费者(独立消费者消费某一个主题数据案例__订阅主题)
    操作系统概述
    LeetCode-895. 最大频率栈【栈,哈希表,设计,有序集合】
    [静态时序分析简明教程(八)]虚假路径
    Linux驱动开发 --- 模块加载和ELF文件
  • 原文地址:https://blog.csdn.net/weixin_42469135/article/details/124957002