Harbor以「項目」爲中心,經過對項目配置「複製策略」,標明須要複製的項目以及鏡像。管理員在複製策略中指明目標實例,即複製的「目的地」,並對它的地址和鏈接時使用的用戶名密碼進行設置。當複製策略被激活時,源項目下的全部鏡像,都會被複制到目標實例;此外,當源項目下的鏡像被添加或刪除(push或delete), 只要策略還在激活狀態,鏡像的變化都會同步到目標實例上去, 以下圖所示:html
1 172.24.8.111 reg.harbor01.com 2 172.24.8.112 reg.harbor02.com
1 root@docker02:~/harbor# cat addhosts.sh 2 #!/bin/sh 3 #****************************************************************# 4 # ScriptName: test.sh 5 # Author: xhy@itzgr.com 6 # Create Date: 2018-10-27 15:48 7 # Modify Author: xhy@itzgr.com 8 #***************************************************************# 9 docker ps | awk '{print $1}'>./dockerlist.txt 10 for id in `cat ./dockerlist.txt` 11 do 12 HOSTS=`docker inspect $id | grep hosts | awk -F "\"" '{print $4}'` 13 echo -e "172.24.8.111 reg.harbor01.com\n172.24.8.112 reg.harbor02.com" >> $HOSTS 14 done
1 root@docker03:~# vi /etc/hosts 2 172.24.8.111 reg.harbor01.com 3 172.24.8.112 reg.harbor02.com 4 root@docker03:~# vi /etc/docker/daemon.json 5 { 6 "insecure-registries": ["http://reg.harbor01.com","http://reg.harbor02.com"] 7 } 8 root@docker03:~# systemctl daemon-reload 9 root@docker03:~# systemctl restart docker.service 10 root@docker03:~# docker login reg.harbor01.com #登陸registry 11 Username: admin 12 Password:
1 root@docker03:~# docker pull hello-world 2 root@docker03:~# docker tag hello-world:latest reg.harbor01.com/copyregistry/hello-world:xhy 3 root@docker03:~# docker push reg.harbor01.com/copyregistry/hello-world:xhy