使用Docker Harbor搭建私有鏡像服務(wù)器和Mirror服務(wù)器

Mirror Registry簡(jiǎn)介

# Mirror是Docker Registry的一種特殊類型,它起到了類似代理服務(wù)器的緩存角色,在用戶和Docker Hub之間做Image的緩存。
# 其基本工作原理是,當(dāng)用戶pull一個(gè)鏡像時(shí),若鏡像在mirror服務(wù)器存在,則直接從mirror服務(wù)器拉取,否則若不存在該鏡像,則由mirror server自動(dòng)代理往dockerhub(可配置)中拉取鏡像,并緩存到mirror服務(wù)器中,當(dāng)用戶再次拉取這個(gè)鏡像時(shí),直接從mirror server中拉取,不需要再次從dockerhub中拉取。

使用Docker Harbor搭建私有服務(wù)器和Mirror服務(wù)器(使用pre-built package)

1 安裝docker和docker-compose
https://docs.docker.com/engine/installation/
https://docs.docker.com/compose/install/
2下載harbor
地址https://github.com/vmware/harbor/releases
3 解壓
$ tar -xzvf harbor-0.3.0.tgz
$ cd harbor
4 修改harbor.cfg文件
$ vim harbor.cfg
修改hostname=172.20.xxx.xx(自己的主機(jī))
(此處暫且使用默認(rèn)賬戶admin/Harbor12345,所以不修改郵箱相關(guān)信息)
5 執(zhí)行./prepare命令
6 修改配置(mirror服務(wù)器和私有服務(wù)器分開部署,因?yàn)閙irror服務(wù)器只能pull,不能push)
6-1 Harbor作為mirror registry —— 修改config/registry/config.yml文件
$ vim config/registry/config.yml
在config.yml文件的最后追加以下配置:
proxy:
  remoteurl: https://registry-1.docker.io
   這樣保證docker pull并不存在于docker harbor中的image時(shí),會(huì)從Docker Hub上去pull,并緩存于mirror服務(wù)器。
   此時(shí)無法從harbor的ui刪除鏡像倉庫。
add-proxy.png
6-2 Harbor作為私服 —— 修改/usr/lib/systemd/system/docker.service文件
$ vim /usr/lib/systemd/system/docker.service
在ExecStart=/usr/bin/dockerd --mtu=1472 --bip=10.1.102.1/24后面添加 --insecure-registry 172.20.xxx.xx:80
edit-docker-service.png
7 重啟docker服務(wù)
$ systemctl daemon-reload
$ service docker restart
8 build并啟動(dòng)
$ docker-compose up -d
9 接下來需要需要配置客戶端(pull/push的機(jī)器,可以為服務(wù)器本機(jī))
$ vim /usr/lib/systemd/system/docker.service
9-1 訪問mirror服務(wù)器的客戶端配置
    在ExecStart=/usr/bin/dockerd --mtu=1472 --bip=10.1.102.1/24后面添加--registry-mirror=http://172.20.141.69:80 
9-2 訪問私有服務(wù)器的客戶端配置
    在ExecStart=/usr/bin/dockerd --mtu=1472 --bip=10.1.102.1/24后面添加 --insecure-registry 172.20.xxx.xx:80
    可以添加多個(gè)服務(wù)器,如添加--insecure-registry 172.20.xxx.xx:80 --insecure-registry 172.20.xxx.aa:80
    ### 上述兩條中的172.20.xxx.xx和172.20.xxx.aa是服務(wù)器上的harbor.cfg的hostname
edit-docker-service-client.png
10 push/pull 鏡像
push時(shí)必須登錄,pull可以不登錄。
操作日志可以登錄頁面訪問。(ui地址為http://172.20.xxx.xx/)
push操作如下:
$ docker tag hello-world 172.20.xxx.xx:80/library/hello-world
$ docker login 172.20.xxx.xx:80
$ docker push 172.20.xxxx.xx:80/library/hello-world

!!!注意:library是harbor中的項(xiàng)目名稱,里面包含的是鏡像倉庫,而hello-world就是鏡像倉庫
pull操作如下

$ docker pull 172.20.xxx.xx:80/library/hello-world
參考文章
1 安裝
https://github.com/vmware/harbor/blob/master/docs/installation_guide.md
2 Harbor作為mirror registry或私有服務(wù)器
http://www.cnblogs.com/puroc/p/5431375.html
http://blog.csdn.net/project_harbor/article/details/51261934
如果harbor出現(xiàn)問題,可以執(zhí)行以下命令重啟harbor
$ docker-compose stop       //停止運(yùn)行容器
$ docker-compose rm         //刪除容器
$ systemctl daemon-reload
$ service docker restart    //重啟docker
$ docker-compose up -d      //啟動(dòng)harbor
注意事項(xiàng)
1 Harbor作為Mirror服務(wù)器時(shí)只能pull不能push了
https://github.com/vmware/harbor/issues/120
回答中還包括問題討論的鏈接,總之最后沒解決,DaoCloud采取的辦法是把用戶私服和mirror分開
2 Harbor作為Mirror服務(wù)器時(shí),不能從ui上刪除鏡像倉庫。
以下是刪除library項(xiàng)目中的hello-world鏡像倉庫時(shí)報(bào)錯(cuò)。僅僅作為私服時(shí)可以順利刪除。
delete-failed.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容