Docker系列11:自建registry(1)

1、registry基礎

一、registry的類別

  • Sponsor Registry:第三方的registry,供用戶和社區使用
  • Mirror Registry:第三方的registry,供用戶使用
  • Vendor Registry:由Docker官方提供的registry
  • Private Registry:私有的registry
    【若是用的環境是阿里雲,那麼用阿里雲的registry是最好的選擇】

    二、自建registry有三種方法

  • 方法1:本地安裝配置registry
  • 方法2:使用官方提供的registry鏡像
  • 方法3:使用Harbor製做registry

2、配置本地的registry

Docker系列11:自建registry(1)

  • 在140節點安裝registry組件
  • 而後將130節點上的鏡推送上來

    第一步:在 140 節點安裝registry組件【在extra源中】

    1)安裝組件nginx

    [root@host2 ~]# yum install docker-registry -y

    2)檢查一下resitory的配置文件docker

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

    【裏面的內容通常不用改動】json

    version: 0.1
    log:
    fields:
    service: registry
    storage:
    cache:
        layerinfo: inmemory
    filesystem:
        rootdirectory: /var/lib/registry
    http:
    addr: :5000

    3)啓動服務vim

    [root@host2 ~]# systemctl start docker-distribution
    [root@host2 ~]# ss -tnl | grep 5000
    LISTEN     0      128       [::]:5000                  [::]:*

    第二步:在 130 節點製做鏡像並上傳到registry

    1)修改hosts文件,實現名稱解析安全

    [root@host1 ~]# echo "172.16.100.3     host2">>/etc/hosts
    [root@host1 ~]# ping host2

    2)給一個現有的鏡像打上標籤
    先隨意找個鏡像tcp

    [root@host1 ~]# docker image ls | head -n2
    REPOSITORY                           TAG                 IMAGE ID           
    base                                            v1.1                ca1046667ac3

    給鏡像打標籤ide

    [root@host1 ~]# docker tag base:v1.1 host2:5000/baseimg:v1-0

    3)編輯docker配置文件
    雖然此時已經制做好了鏡像,可是還不能推送,由於docker默認用的https協議,而咱們的registry用的是http協議阿里雲

    [root@host1 ~]# vim /etc/docker/daemon.json
    {
    "registry-mirrors": [
        "https://registry.docker-cn.com",
        "https://mzxx8xy8.mirror.aliyuncs.com"
    ],
    "hosts": ["tcp://0.0.0.0:3725", "unix://var/run/docker.sock"],
    "insecure-registries": ["host2:5000"]
    }

    重啓一下服務unix

    [root@host1 ~]# systemctl daemon-reload
    [root@host1 ~]# systemctl restart docker

    4)推送鏡像rest

    [root@host1 ~]# docker push host2:5000/baseimg:v1-0

    推送的鏡像會保存在服務的特定目錄

    [root@host2 ~]# ls /var/lib/registry/docker/registry/v2/repositories/
    baseimg

    第三步:在 150 節點下載鏡像

    1)修改docker配置文件,運行不安全的json
    同:第二步
    2)下載鏡像

    [root@host2 ~]# docker pull host2:5000/baseimg:v1-0

    3、使用官方的registry

    官方經過鏡像發佈了一個registry,只要啓動容器就能夠了
    Docker系列11:自建registry(1)

    第一步:拉取鏡像並啓動,製做成registry

    1)下載鏡像

    [root@host1 ~]# docker pull registry

    2)第二步:建立目錄

    [root@host1 ~]# mkdir -p /opt/{auth,data}
    [root@host1 ~]# ls /opt/
    auth  data

    3)第三步:建立認證文件

    [root@host1 ~]# docker run --entrypoint \
    > htpasswd registry -Bbn zxhk 123 > /opt/auth/htpasswd
    [root@host1 ~]# echo "0">/proc/sys/net/ipv4/ip_forward

    4)第四步:建立容器

    [root@host1 ~]# docker run -d -p 6000:5000 \
    > --restart=always --name registry1 \
    > -v /opt/auth:/auth -v /opt/data:/tmp/registry \
    > -e "REGISTRY_AUTH=htpasswd" \
    > -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
    > -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \
    > registry

    第二步:在其餘節點使用這個registry

    1)修改docker配置文件,容許不安全的json

    [root@host2 ~]# vim /etc/docker/daemon.json
    {
    "registry-mirrors": [
        "https://registry.docker-cn.com",
        "https://mzxx8xy8.mirror.aliyuncs.com"
    ],
    "hosts": ["tcp://0.0.0.0:3725", "unix://var/run/docker.sock"],
    "insecure-registries": ["172.16.100.3:6000"]
    }

    2)給鏡像打標籤

    [root@host1 ~]# docker tag nginx:1.17-alpine 172.16.100.3:6000/nginx:v1-1

    3)登陸registry

    [root@host1 ~]# docker login http://172.16.100.3:6000

    4)推送鏡像

    [root@host1 ~]# docker push 172.16.100.3:6000/nginx:v1-1
相關文章
相關標籤/搜索