harbor私服使用docker推送和拉取鏡像
harbor私服使用docker、docker-compose和harbor安裝部署: https://www.cnblogs.com/CooderWang/p/15796114.html
在實際開發中,常常會將harbor部署到公網,並配置好域名和https。在開發者機器上build好鏡像之后,再push到公網的harbor上。最后項目上線時再到服務器上pull鏡像。因為harbor在公網上所以咱們的服務也能訪問的到。
接下來看看如何將自己打包好的鏡像推送到harbor私服,然后在其它機器上拉取鏡像
安裝后的一些配置
首先需要創建一個用戶
點擊創建用戶

輸入用戶名密碼郵箱這些不用多說,注意這些信息在推送鏡像的時候會用到,不要隨便設一個!

創建用戶后如下

然后創建一個鏡像倉庫
先來看公開倉庫,點擊這個按鈕

為倉庫起名后點擊確定

這樣就創建了一個鏡像倉庫了

點進去給這個鏡像倉庫分配管理用戶

輸入之前創建的用戶名,確定即可

推送本地docker鏡像到harbor私服
接下就是樣演示推送鏡像到harbor私服了,點擊鏡像倉庫這一欄。有一個推送鏡像的按鈕。點一下會出現推送命令。注意必須使用這個推送命令所示的前綴,不然是推送不了的。

首先我的本機linux上有名為 192.168.10.11:81/test/demo1:latest
的鏡像,需要推送到harbor私服上。注意我這里已經是改完鏡像名字符合上面要求的前綴了,關於鏡像的改名可以看看我的這篇文章https://www.jianshu.com/p/caecb4fc0c35

使用命令推送
docker push 192.168.10.11:81/test/demo1:latest
報錯如下
The push refers to repository [192.168.10.11:81/test/demo1]
Get https://192.168.10.11:81/v2/: http: server gave HTTP response to HTTPS client
提示推送鏡像報docker客戶端需要https請求,要么給harbor配置域名+https,要么修改dockr客戶端配置,讓它支持http。如果私服只是內網使用當然改docker客戶端比較方便啦~
編輯daemon.json文件,加上insecure-registries的配置
vi /etc/docker/daemon.json
注意這個192.168.10.11:81 的 81 端口是 harbor的http訪問端口,通過它來訪問harbor的UI管理頁面。當然它默認是80,我將之改為了81
{ "registry-mirrors": ["http://hub-mirror.c.163.com"],"insecure-registries":["192.168.10.11:81"] }
改完后重啟docker服務
systemctl daemon-reload
systemctl restart docker
再次執行推送命令,報錯
[root@localhost harbor]# docker push 192.168.10.11:81/test/demo1:latest
The push refers to repository [192.168.10.11:81/test/demo1]
f8c4d6c65078: Preparing
d132b54fabdd: Preparing
35c20f26d188: Preparing
c3fe59dd9556: Preparing
6ed1a81ba5b6: Preparing
a3483ce177ce: Waiting
ce6c8756685b: Waiting
30339f20ced0: Waiting
0eb22bfb707d: Waiting
a2ae92ffcd29: Waiting
denied: requested access to the resource is denied
因為沒有登錄到harbor私服的原因,那么就登錄吧
- 注意使用docker login 192.168.10.11:81 登錄的 81端口也是harbor的web端口,默認是80。被我改成81了
[root@localhost harbor]# docker login 192.168.10.11:81 Username: yinkai 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

再次推送,這樣子算是成功了

查看test項目下果然有鏡像了

點進去看看

在其它機器上拉取已上傳的鏡像
最后來看看如何拉取私服上的鏡像。首先點擊去鏡像倉庫,找到剛上傳的demo1鏡像。如圖點擊復制pull命令

在服務器上執行命令即可
docker pull 192.168.10.11:81/test/demo1:latest

使用docker images 查看鏡像

拉取成功~