Docker已經上市不少年,不是什麼新鮮事物了,不少企業或者開發同窗之前也很少很多有所接觸,可是有實操經驗的人很少,本系列教程主要偏重實戰,儘可能講乾貨,會根據本人理解去作闡述,具體官方概念能夠查閱官方教程,由於本系列教程對前一章節有必定依賴,建議先學習前面章節內容。node
本系列教程導航:linux
教程目的:nginx
官方概念: Harbor是一個開放源代碼容器映像鏡像表,可經過基於角色的訪問控制來保護鏡像,掃描鏡像中的漏洞並將鏡像簽名爲受信任。 做爲CNCF孵化項目,Harbor提供合規性,性能和互操做性,以幫助您跨Kubernetes和Docker等雲原生計算平臺持續,安全地管理鏡像。git
簡單來講,Harbor就是一個開源的鏡像管理倉庫,相似Github同樣,可讓咱們存放一些鏡像文件github
更多詳細內容,能夠查看Harbor 官方文檔redis
有動手跟着我前面教程練習的同窗應該都有感覺,以前的Springboot項目每次都須要在服務器建立鏡像,當我有多臺服務器須要用到這個鏡像,我還得重複在每臺服務器上建立一次,那有沒有一箇中間存儲服務幫咱們管理這些鏡像,讓全部的服務器能夠共享這個鏡像文件呢?Harbor的做用就是幫咱們管理鏡像,採用分佈式架構,讓咱們能夠在任意服務器拉去咱們構建好的鏡像文件。而後又會有人問咱們不是已經有docker hub
或者 docker hub
這些遠程倉庫了嗎?確實,可是當咱們須要搭建一些私有鏡像倉庫,不想把公司項目對外公開的時候,Harbor就頗有用了,就像不少公司也會在本身公司搭建私有的nexus服務器來管理公司內部的應用package。 docker
到github選擇一個harbor
release版本下載 https://github.com/goharbor/harbor/releases
json
上傳到你的linux服務器,我這裏沿用上一章建立的manager節點瀏覽器
[root@manager-node harbor]# ls
common.sh harbor.yml LICENSE
harbor.v1.10.1.tar.gz install.sh prepare
複製代碼
上面是harbor應用解壓後的文件安全
修改harbor配置文件 harbor.yml
#設置域名
hostname: 192.168.101.11
#設置http參數
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 8090
#設置管理員密碼
harbor_admin_password: evan123
#屏蔽https
#https:
# https port for harbor, default is 443
# port: 443
複製代碼
上面修改了hostname爲我虛擬機的ip,端口把默認80
端口替換成8090
,而且修改了管理員密碼爲evan123
。須要注意,我這裏屏蔽了https
,若是你們須要開啓https
,須要配置證書和key到指定位置
Docker默認是不支持http訪問註冊表,不然後面使用docker去訪問harbor服務,會報以下錯誤:
http: server gave HTTP response to HTTPS client
複製代碼
這裏須要先修改下/etc/docker/daemon.json
配置,加入如下配置
{
"insecure-registries" : ["192.168.101.11:8090"]
}
複製代碼
重啓docker服務
systemctl restart docker
複製代碼
假如沒有Docker
環境,harbor
會啓動報錯
[root@manager-node harbor]# sh install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 19.03.7
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.25.0
[Step 2]: loading Harbor images ...
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
複製代碼
須要先安裝Docker
和docker-compose
組件,這裏就很少說了,你們能夠參考前面章節的安裝教程
當啓動Docker後,執行install.sh
會自動完成安裝
[root@manager-node harbor]# sh install.sh
...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-portal ... done
Creating registry ... done
Creating redis ... done
Creating harbor-db ... done
Creating registryctl ... done
Creating harbor-core ... done
Creating nginx ... done
Creating harbor-jobservice ... done
✔ ----Harbor has been installed and started successfully.----
複製代碼
上面顯示已經安裝成功了
在瀏覽器輸入上面咱們配置的ip和端口192.168.101.11:8090
,就會看到harbor
登錄頁面
這裏使用咱們上面的定義的密碼登錄
admin
evan123
點擊New
會進入項目建立對話框,這裏填入項目名稱便可,這裏的訪問級別我選擇public
在使用Harbor以前,要在docker環境登錄Harbor服務
[root@manager-node harbor]# docker login 192.168.101.11:8090
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
複製代碼
[root@manager-node credit-facility]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
credit-facility-image latest 28948b936fac 2 days ago 130MB
複製代碼
credit-facility-image
打個標籤,新標籤爲credit-facility:1.0
docker tag credit-facility-image:latest credit-facility:1.0
複製代碼
credit-facility
進行發佈[root@manager-node harbor]# docker push 192.168.101.11:8090/credit-facility/credit-facility-image
The push refers to repository [192.168.101.11:8090/credit-facility/credit-facility-image]
21f243c9904f: Pushed
edd61588d126: Pushed
9b9b7f3d56a0: Pushed
f1b5933fe4b5: Pushed
latest: digest: sha256:86a6289143d0a8a4cc94880b79af36416d07688585f8bb1b09fd4d50cd166f46 size: 1159
複製代碼
從上面顯示結果能夠看到,咱們已經成功上傳鏡像到Harbor倉庫了
[root@manager-node harbor]# docker image rm 192.168.101.11:8090/credit-facility/credit-facility-image:latest
Untagged: 192.168.101.11:8090/credit-facility/credit-facility-image:latest
Untagged: 192.168.101.11:8090/credit-facility/credit-facility-image@sha256:86a6289143d0a8a4cc94880b79af36416d07688585f8bb1b09fd4d50cd166f46
複製代碼
[root@manager-node harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
複製代碼
如今本地已經沒有任何鏡像
3.從Harbor倉庫拉去鏡像
[root@manager-node harbor]# docker pull 192.168.101.11:8090/credit-facility/credit-facility-image:latest
latest: Pulling from credit-facility/credit-facility-image
Digest: sha256:86a6289143d0a8a4cc94880b79af36416d07688585f8bb1b09fd4d50cd166f46
Status: Downloaded newer image for 192.168.101.11:8090/credit-facility/credit-facility-image:latest
192.168.101.11:8090/credit-facility/credit-facility-image:latest
複製代碼
鏡像已經拉取成功
4.在查看本地鏡像列表驗證下
[root@manager-node harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.101.11:8090/credit-facility/credit-facility-image latest 28948b936fac 2 days ag
複製代碼
咱們的鏡像已經成功安裝到本地了,這樣即使咱們之後換了一臺服務器,也能夠隨時從Harbor倉庫拉取鏡像,不須要依賴本地服務器