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 [::]:*
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
1)修改docker配置文件,運行不安全的json
同:第二步
2)下載鏡像
[root@host2 ~]# docker pull host2:5000/baseimg:v1-0
官方經過鏡像發佈了一個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
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