• 9、Docker私有registry


    Docker Registry分类

    Docker 默认是使用https的,但是如果在自己得私有局域网中,你指明使用http也是可以的。

    Registry主要的作用是托管镜像;

    运行docker registry的方式一:

    registry运行在容器中,容器的文件是随着容器的消息而被删除。所以要为registry定义一个存储卷,这个存储卷不要放在docker host本地,而是要使用网络存储。

    运行docker registry的方式二演示:

    注意在node2上创建

    [root@node2 ~]# yum info docker-registry   //查看registry的版本号  

    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * epel: mirror.lzu.edu.cn
     * extras: mirrors.163.com
     * updates: mirror.lzu.edu.cn
    Available Packages
    Name        : docker-registry
    Arch        : x86_64
    Version     : 0.9.1
    Release     : 7.el7
    Size        : 123 k
    Repo        : extras/7/x86_64
    Summary     : Registry server for Docker
    URL         : https://github.com/docker/docker-registry
    License     : ASL 2.0
    Description : Registry server for Docker (hosting/delivering of repositories and images).

    [root@node2 ~]# yum install docker-registry

    虽然安装的是rigstry,但是包名是 docker-ditribution 上述版本与docker官网的最新版本相差无几 https://hub.docker.com/_/registry?tab=tags;

    [root@node2 ~]# rpm -ql docker-distribution

    /etc/docker-distribution/registry/config.yml   //配置文件
    /usr/bin/registry
    /usr/lib/systemd/system/docker-distribution.service
    /usr/share/doc/docker-distribution-2.6.2
    /usr/share/doc/docker-distribution-2.6.2/AUTHORS
    /usr/share/doc/docker-distribution-2.6.2/CONTRIBUTING.md
    /usr/share/doc/docker-distribution-2.6.2/LICENSE
    /usr/share/doc/docker-distribution-2.6.2/MAINTAINERS
    /usr/share/doc/docker-distribution-2.6.2/README.md
    /var/lib/registry    //存放数据路径

    [root@node2 ~]# vim /etc/docker-distribution/registry/config.yml 

    version: 0.1 
    log:
      fields:
        service: registry    //服务
    storage:
        cache:
            layerinfo: inmemory   //缓存在内存中 
        filesystem:
            rootdirectory: /var/lib/registry    //数据存储路径
    http:
        addr: :5000     //5000是端口,地址没有给出表示本机所有可用地址,这里是http协议,标准端口应该是80端口,如果是https协议则标准端口是443

    [root@node2 ~]# systemctl start docker-distribution

    [root@node2 ~]# ss -tnl | grep 5000
           LISTEN              0           128             :::5000          :::*

    以上docker私有仓库就准备好了

    [root@node1 ~]# docker image ls   //显示node1制作的镜像,把node1服务器上的镜像poll到node2的仓库里面

    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    tinyhttpd           v0.1-10             c0c7f3d670e2        28 hours ago        8.28MB   //tinyhttpd这里标记的都是docker hub的标记,而且是顶层仓库,是无法直接推到私有仓库的,要打标
    tinyhttpd           v0.1-7              31c87ab706ef        29 hours ago        7.27MB
    tinyhttpd           v0.1-6              182fd6cb55e0        33 hours ago        7.27MB
    tinyhttpd           v0.1-5              a4edf21d7f10        34 hours ago        7.27MB
    tinyhttpd           v0.1-4              ffd35e42c975        47 hours ago        7.29MB
    tinyhttpd           v0.1-3              36fff46e7087        47 hours ago        2.24MB
    tinyhttpd           v0.1-2              948f2959ddb4        2 days ago          1.22MB
    tinyhttpd           v0.1-1              026022e873de        2 days ago          1.2MB
    beisen/httpd        v0.2                bf9c668b1196        3 weeks ago         1.2MB
    beisen/httpd        v0.1-1              9a9506b58e22        3 weeks ago         1.2MB
    nginx               1.14-alpine         cafef9fe265b        3 weeks ago         16MB
    redis               4-alpine            1e985c88d45b        3 weeks ago         35.5MB
    busybox             latest              d8233ab899d4        6 weeks ago         1.2MB

    [root@node2 ~]# ifconfig  //要使用node2上对外通信的IP地址,非docker hub就必须给出docker registry的服务器地址、端口。

    [root@node1 ~]# docker tag tinyhttpd:v0.1-10 node2:5000/tinyhttpd:v0.1-10   //在node1上打标,加红加粗部分(tinyhttpd表示顶层仓库)表示顶层仓库

    [root@node1 ~]# docker image ls

        node2:5000/tinyhttpd   v0.1-10             c0c7f3d670e2        28 hours ago        8.28MB   //查看打包的镜像

    [root@node1 ~]# docker push node2:5000/tinyhttpd:v0.1-10    //往node2中推送镜像,这里由于只有一个镜像,标签(v0.1-10)可要可不要,如果不给标签,则推送整个仓库。
        The push refers to repository [node2:5000/tinyhttpd]
        Get https://node2:5000/v2/: http: server gave HTTP response to HTTPS client   //这里报错,因为docker默认是https协议,此处客户端是http协议,而服务器端是https协议。

    由于本次演示是在内网,所以可以不使用https协议,要使用http协议必须进行配置,把它标记为非加密非安全的docker registry。

     官方手册(完整的可用参数列表):             

    https://docs.docker.com/engine/reference/commandline/dockerd/#run-multiple-daemons 

     "insecure-registries": [],   //把此项添加到/etc/docker/daemon.json

    [root@node1 ~]# vim /etc/docker/daemon.json    //在node1中进行配置

    {
    "registry-mirrors": ["https://registry.docker-cn.com"],
    "insecure-registries": ["node2:5000"],   //添加此行
    "bip": "10.0.0.1/16"
    }

    [root@node1 ~]# systemctl restart docker   //注意这里更改的是node1,相对于docker registry(node2是服务器端),node1是客户端。

    [root@node1 ~]# docker push node2:5000/tinyhttpd:v0.1-10   //此时就可以成功了

    The push refers to repository [node2:5000/tinyhttpd]
    199778bdbe15: Pushed    //这表示一层,每一层都单独存放
    9cf8d73c614a: Pushed 
    868d862401c1: Pushed 
    adab5d09ba79: Pushed 
    v0.1-10: digest: sha256:3bd3dc5a7295ab9a2affbf7793e1dc1272f515c5aeec3d3417907b15c6d1ad04 size: 1156

    [root@node2 ~]# cd /var/lib/registry/docker/registry/v2/repositories/tinyhttpd/_
       _layers/ _manifests/ _uploads/
    [root@node2 ~]# cd /var/lib/registry/docker/registry/v2/repositories/tinyhttpd/_layers/sha256/
       66bf463ec427c266523a37e3c405c5d40d1a20f5f7b40c8f26fa11cc27ed82ac/
       697743189b6d255069caf6c455be10c7f8cae8076c6f94d224ae15cd41420e87/
       92dba7e5a2cbf2a9550b8783ef02210c6c2a00b45b621ba8b00af7bb9da3bb58/
       c0c7f3d670e214de0dfaa3dee5907591308ca123746066e1c1245263277fd815/
       e535bb7265a642ef3cc982d8e80bcf2559ff3cef66be8bfcc2758a77fca7d947/

    [root@node2 ~]# ls /var/lib/registry/docker/registry/v2/repositories/tinyhttpd/_layers/sha256/66bf463ec427c266523a37e3c405c5d40d1a20f5f7b40c8f26fa11cc27ed82ac
       link    //此处就是链接到node1中

    如果想在node2上下载刚才push的镜像,同时使用http服务,就需要对node2上的配置文件进行更改。

    [root@node2 ~]# vim /etc/docker/daemon.json

      

  • 相关阅读:
    Shared variable in python's multiprocessing
    File checksum
    Windows createprocess linux fork
    人工调用系统调用
    如何提高团队开发效率
    Redis' High Availability
    并发MD5计算方法
    开博宣言
    NYOJ 55 懒省事的小明
    HDU 1237 简单计算器
  • 原文地址:https://www.cnblogs.com/hanshanxiaoheshang/p/10639293.html
Copyright © 2020-2023  润新知