需求:
公司內部將制作的docker鏡像推送到公司私有Harbor倉庫,客戶可以通過公網域名直接拉取公司Harbor公開項目下的鏡像,通過分配的Harbor用戶名密碼可以拉取對應的私有項目下的鏡像。
安裝Harbor:
參考這篇博文:https://www.cnblogs.com/zhangmingcheng/p/12753959.html
Harbor配置nginx代理:
Harbor默認只能使用harbor.yml
中hostname指定的ip或主機名作為web訪問地址,但在實際使用過程中,一般不允許ip地址或者主機名直接暴露在外訪問,故需要配置nginx代理,通過代理后指定的地址進行訪問。
- 通過nginx為harbor后端暴露的地址及端口設置proxy地址,來源於harbor配置文件中的hostname及port
- 修改harbor配置文件再次使用nginx設置的proxy地址
通過修改nginx的配置文件中server模塊設置代理地址以及端口等信息,若harbor與nginx不在同一個服務器上或harbor不止一個服務器,還需要通過nginx的upstream模塊來實現請求后端realserver及負載均衡,nginx配置文件修改處示例如下:
Harbor設置:
通過nginx配置了代理之后,還需要修改harbor的配置文件設置proxy地址:
vim harbor.yml
web驗證:
通過瀏覽器訪問http://xx.xx.com:port
訪問代理后地址
客戶阿里雲服務器測試:
1、直接拉取public項目下的鏡像:
2、拉取私有項目下的鏡像
遇到的問題:
1、request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)錯誤:
[root@iZrj9j76z8dlull9vqa4tqZ ~]# docker pull harbor.xxx.cn:443/1-1/mytomcat:8.5.52
Error response from daemon: Head https://harbor.xxx.cn:443/v2/1-1/mytomcat/manifests/8.5.52: Get http://10.20.31.104:5000/service/token?scope=repository%3A1-1%2Fmytomcat%3Apull&service=harbor-registry: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
解決方案:修改harbor.yml配置文件,取消external_url注釋,設置為:external_url: https://harbor.xxx.cn,注意https://harbor.xxx.cn后面不能寫端口。
然后,docker-compose down停止所有服務,刪除當前配置目錄:rm -rf ./common/config下配置清單,重新執行install.sh生成配置,即可解決
2、dial tcp: lookup harbor.xxx.cn;: no such host錯誤:
解決方案:修改harbor.yml配置文件,hostname字段只寫harbor.xxx.cn,域名前面不要寫http/https協議。
3、Harbor重啟失敗,報ERROR: for harbor-portal Cannot start service portal: failed to initialize logging driver: dial tcp 127.0.0.1:1514: connect: connection refused錯誤
解決方案:https://blog.csdn.net/qq_39680564/article/details/107237110
注意:只要修改了harbor.yml,要想讓配置生效,需要刪除當前配置目錄:rm -rf ./common/config下配置清單,重新執行install.sh生成配置。
參考:https://blog.csdn.net/lcl_xiaowugui/article/details/105422794
參考:https://blog.csdn.net/fengchao169/article/details/106223253/
參考:https://www.cnblogs.com/liucx/p/12981023.html
參考:https://blog.csdn.net/qq_39680564/article/details/107237110
參考:http://www.ttlsa.com/nginx/resolve-https-rewrite-to-http/