docker——harbor


為什么要用harbor?

   在實際生產運維中,往往需要把鏡像發布到幾十、上百台或更多的節點上。這時單台Docker主機上鏡像已無法滿足,項目越來越多,鏡像就越來越多,都放到一台Docker主機上是不行的,我們需要一個像Git倉庫一樣系統來統一管理鏡像。這里介紹的是一個企業級鏡像倉庫Harbor,將作為我們容器雲平台的鏡像倉庫中心。
   Habor是由VMWare公司開源的容器鏡像倉庫。事實上,Habor是在Docker-Registry上進行了相應的企業級擴展,從而獲得了更加廣泛的應用,這些新的企業級特性包括:管理用戶界面,基於角色的訪問控制 ,AD/LDAP集成以及審計日志等,足以滿足基本企業需求。

Harbor和Registry的比較:

 

Harbor和Registry都是Docker的鏡像倉庫,但是Harbor作為更多企業的選擇,是因為相比較於Regisrty來說,它具有很多的優勢。
1、提供分層傳輸機制,優化網絡傳輸
Docker鏡像是是分層的,而如果每次傳輸都使用全量文件(所以用FTP的方式並不適合),顯然不經濟。必須提供識別分層傳輸的機制,以層的UUID為標識,確定傳輸的對象。
2、提供WEB界面,優化用戶體驗
只用鏡像的名字來進行上傳下載顯然很不方便,需要有一個用戶界面可以支持登陸、搜索功能,包括區分公有、私有鏡像。
3、支持水平擴展集群
當有用戶對鏡像的上傳下載操作集中在某服務器,需要對相應的訪問壓力作分解。
4、良好的安全機制
企業中的開發團隊有很多不同的職位,對於不同的職位人員,分配不同的權限,具有更好的安全性。
5、Harbor提供了基於角色的訪問控制機制,並通過項目來對鏡像進行組織和訪問權限的控制。kubernetes中通過namespace來對資源進行隔離,在企業級應用場景中,通過將兩者進行結合可以有效將kubernetes使用的鏡像資源進行管理和訪問控制,增強鏡像使用的安全性。尤其是在多租戶場景下,可以通過租戶、namespace和項目相結合的方式來實現對多租戶鏡像資源的管理和訪問控制。

搭建harbor:

第一步:

yum install epel-release            #下載擴展源
yum install -y python-pip
pip install --upgrade pip
pip install docker-compose

第二步:下載harbor

https://github.com/goharbor/harbor/releases

第三步:解壓harbo安裝包

[root@localhost ~]# tar xf harbor-offline-installer-v1.8.2.tgz

第四步:修改配置文件

[root@localhost ~]# cd harbor/
[root@localhost harbor]# vim harbor.yml
...
hostname: 192.168.59.200
...

第五步:執行harbor腳本

[root@localhost harbor]# ./install.sh

第六步:瀏覽器配置

...
賬號/密碼: admin/Harbor12345
harbor_admin_password: Harbor12345 #harbor.yml
...

 

 

 

第七步:鏡像改名

[root@localhost harbor]# docker tag httpd:latest 192.168.59.200/test/httpd:v1

第八步:修改docker配置文件

[root@localhost harbor]# vim /etc/docker/daemon.json 
...
{
"registry-mirrors": ["https://6wnyrhwf.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.59.200:8878"],
"insecure-registries": ["192.168.59.200"]
}
...

第九步:重啟docker

[root@localhost harbor]# systemctl restart docker

第十步:啟動harbor

[root@localhost harbor]# docker-compose start
Starting log ... done
Starting postgresql ... done
Starting redis ... done
Starting registry ... done
Starting core ... done
Starting jobservice ... done
Starting portal ... done
Starting proxy ... done
Starting registryctl ... done 

第十一步:需要登錄harbor

[root@localhost harbor]# docker login 192.168.59.200
Username: admin
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

第十二步:推送鏡像至harbor

[root@localhost harbor]# docker push 192.168.59.200/test/httpd
The push refers to repository [192.168.59.200/test/httpd]
0f8d971d177b: Pushed 
97fd31ecd005: Pushed 
82155933cfa6: Pushed 
2fd9f57029b0: Pushed 
02bd518ef304: Pushed 
b8342f9976fc: Pushed 
2c833f307fd8: Pushed 

第十三步:harbor查看

 

 

第十四步:拉取鏡像

[root@localhost harbor]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.59.200/test/httpd v1 fb2f3851a971 18 months ago 178MB
[root@localhost harbor]# docker image rm -f fb2f3851a971
[root@localhost harbor]# docker pull 192.168.59.200/test/httpd:v1 
v1: Pulling from test/httpd
3d77ce4481b1: Pull complete 
73674f4d9403: Pull complete 
d266646f40bd: Pull complete 
ce7b0dda0c9f: Pull complete 
01729050d692: Pull complete 
014246127c67: Pull complete 
7cd2e04cf570: Pull complete 
Digest: sha256:58270ec746bed598ec109aef58d495fca80ee0a89f520bd2430c259ed31ee144
Status: Downloaded newer image for 192.168.59.200/test/httpd:v1
192.168.59.200/test/httpd:v1
[root@localhost harbor]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.59.200/test/httpd v1 fb2f3851a971 18 months ago 178MB

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM