Mirror Registry簡介
# Mirror是Docker Registry的一種特殊類型,它起到了類似代理服務(wù)器的緩存角色碘橘,在用戶和Docker Hub之間做Image的緩存宣虾。
# 其基本工作原理是悦荒,當(dāng)用戶pull一個鏡像時,若鏡像在mirror服務(wù)器存在,則直接從mirror服務(wù)器拉取响逢,否則若不存在該鏡像,則由mirror server自動代理往dockerhub(可配置)中拉取鏡像唤崭,并緩存到mirror服務(wù)器中拷恨,當(dāng)用戶再次拉取這個鏡像時,直接從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(自己的主機)
(此處暫且使用默認賬戶admin/Harbor12345,所以不修改郵箱相關(guān)信息)
5 執(zhí)行./prepare命令
6 修改配置(mirror服務(wù)器和私有服務(wù)器分開部署芦疏,因為mirror服務(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時,會從Docker Hub上去pull酸茴,并緩存于mirror服務(wù)器分预。
此時無法從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并啟動
$ docker-compose up -d
9 接下來需要需要配置客戶端(pull/push的機器薪捍,可以為服務(wù)器本機)
$ 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
可以添加多個服務(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時必須登錄,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中的項目名稱,里面包含的是鏡像倉庫被济,而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 //停止運行容器
$ docker-compose rm //刪除容器
$ systemctl daemon-reload
$ service docker restart //重啟docker
$ docker-compose up -d //啟動harbor
注意事項
1 Harbor作為Mirror服務(wù)器時只能pull不能push了
https://github.com/vmware/harbor/issues/120
回答中還包括問題討論的鏈接,總之最后沒解決溉潭,DaoCloud采取的辦法是把用戶私服和mirror分開
2 Harbor作為Mirror服務(wù)器時净响,不能從ui上刪除鏡像倉庫。
以下是刪除library項目中的hello-world鏡像倉庫時報錯喳瓣。僅僅作為私服時可以順利刪除馋贤。
delete-failed.png