Docker私有倉(cāng)庫(kù)harbor的搭建步驟
本篇文章主要介紹 Docker 私有倉(cāng)庫(kù) harbor 的搭建,搭建成功后測(cè)試鏡像的上傳和下載。
一、實(shí)驗(yàn)環(huán)境
本文是在 CentOS 7.9 上進(jìn)行配置,環(huán)境如下所示。
[root@k8s-master node]# cat /etc/centos-release CentOS Linux release 7.9.2009 (Core) [root@k8s-master imagesJar]# docker --version Docker version 1.13.1, build 7d71120/1.13.1 [root@k8s-master imagesJar]# docker-compose --version docker-compose version 1.18.0, build 8dd22a9 [root@k8s-master imagesJar]#
二、安裝 harbor
2.1 安裝 docker 和 docker-compose
首先,需要在服務(wù)器上安裝 docker 和 docker-compose,執(zhí)行如下命令。
[root@k8s-master node]# yum install docker docker-compose
2.2 安裝 harbor
在服務(wù)器上執(zhí)行如下命令,下載 harbor 軟件包。
[root@k8s-master node]# wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.5.3.tgz
下載比較慢,可以通過(guò)迅雷下載。
解壓下載的壓縮包,執(zhí)行命令如下。
[root@k8s-master harbor]# tar zxvf harbor-offline-installer-v1.5.3.tgz
執(zhí)行命令拷貝解壓后的目錄到 /opt 目錄下,執(zhí)行命令如下所示。
[root@k8s-master harbor]# mv harbor /opt
進(jìn)入到 /opt/harbor 目錄下,修改文件 harbor.cfg,修改如下字段。
hostname = 192.168.231.152 # 修改 IP 地址為本機(jī) IP
執(zhí)行如下命令,安裝 harbor。
[root@k8s-master harbor]# ./prepare [root@k8s-master harbor]# ./install.sh
問(wèn)題 1:
[node@k8s-master harbor]$ sudo ./install.sh ? Please set hostname and other necessary attributes in harbor.cfg first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients. Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.cfg bacause notary must run under https. Please set --with-clair if needs enable Clair in Harbor [node@k8s-master harbor]$
解決方法:在 harbor.cfg 配置文件中僅保留一個(gè) hostname 字段。:
問(wèn)題 2:
執(zhí)行 install.sh 腳本的時(shí)候如下報(bào)錯(cuò)如下。
ERROR: for nginx Cannot start service proxy: b'driver failed programming external connectivity on endpoint nginx (b08a457eb0d19583b0d42a53137a3e8d3a0bc89813b1def8afef7df1d85e1411): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use'
ERROR: for proxy Cannot start service proxy: b'driver failed programming external connectivity on endpoint nginx (b08a457eb0d19583b0d42a53137a3e8d3a0bc89813b1def8afef7df1d85e1411): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use'
ERROR: Encountered errors while bringing up the project.
說(shuō)明本機(jī) 80 端口占用了,可以
[node@k8s-master harbor]$ netstat -natp | grep 80
查找到 80 端口對(duì)應(yīng)的進(jìn)程,通過(guò) kill 命令停止進(jìn)程。
2.3 登錄 harbor UI 界面
在瀏覽器輸入 192.168.231.152/harbor,進(jìn)入 harbor UI 界面,如下所示。

用戶(hù)名和密碼如下所示。
用戶(hù)名:admin
密碼:Harbor12345
密碼在 /opt/harbor/harbor.cfg 中配置,默認(rèn)是 Harbor12345
登錄后界面如下所示。

三、測(cè)試上傳和下載鏡像
先來(lái)看下 docker 的常用命令,如果想直接看測(cè)試,移步到 2.2 上傳鏡像即可。
3.1 docker 常用命令
(1)docker save
將指定鏡像打包成 tar,方便鏡像移動(dòng)。
docker save -o /root/打包名.tar 鏡像名:版本號(hào)
例如:
[node@k8s-master dockerImages]$ sudo docker save -o ./demo-1.2.0.tar test/demo:1.2.0 [sudo] node 的密碼: [node@k8s-master dockerImages]$ ls demo-1.2.0.tar [node@k8s-master dockerImages]$
執(zhí)行上述 docker save 命令會(huì)在當(dāng)前目錄下出現(xiàn) demo-1.2.0.tar 包,將該包復(fù)制到別的機(jī)器,執(zhí)行docker load 命令就完成 docker 鏡像的轉(zhuǎn)移了。
(2)docker load
用于載入打包好的鏡像。例如:
[node@k8s-node-1 dockerImages]$ sudo docker load -i demo-1.2.0.tar 9c742cd6c7a5: Loading layer [==================================================>] 129.2 MB/129.2 MB 03127cdb479b: Loading layer [==================================================>] 11.3 MB/11.3 MB 293d5db30c9f: Loading layer [==================================================>] 19.31 MB/19.31 MB 5c384ea5f752: Loading layer [==================================================>] 12.32 MB/12.32 MB 990c5138f5d1: Loading layer [==================================================>] 3.584 kB/3.584 kB 1aaddf64804f: Loading layer [==================================================>] 108.3 MB/108.3 MB 0a8cde955e2b: Loading layer [==================================================>] 3.584 kB/3.584 kB 0931afb63541: Loading layer [==================================================>] 16.5 MB/16.5 MB Loaded image: test/demo:1.2.0 [node@k8s-node-1 dockerImages]$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE test/demo 1.2.0 fff004fa39a7 11 hours ago 290 MB docker.io/nginx alpine 4937520ae206 3 weeks ago 41.4 MB docker.io/nginx latest eb4a57159180 3 weeks ago 187 MB registry.access.redhat.com/rhel7/pod-infrastructure latest 99965fb98423 5 years ago 209 MB [node@k8s-node-1 dockerImages]$
(3)docker tag
用于給鏡像打標(biāo)簽,語(yǔ)法格式如下所示。
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
(4)docker push
將本地的鏡像上傳到鏡像倉(cāng)庫(kù),要先登陸到鏡像倉(cāng)庫(kù)。語(yǔ)法格式如下所示。
docker push [OPTIONS] NAME[:TAG]
3.2 上傳鏡像
(1)登錄 Harbor
首先,需要修改配置,修改 /etc/docker/daemon.json 文件,添加如下內(nèi)容。
{
"insecure-registries": ["192.168.231.152"]
}其中,IP 是 Harbor 倉(cāng)庫(kù) IP。然后執(zhí)行如下命令,重啟服務(wù)。
[root@k8s-master harbor]# systemctl daemon-reload [root@k8s-master harbor]# systemctl restart docker
然后,需要在本地的服務(wù)器(Linux 機(jī)器)上登錄,執(zhí)行如下命令登錄。
[root@k8s-master harbor]# docker login 192.168.231.152
其中,IP 是 Harbor 倉(cāng)庫(kù)的 IP,然后輸入用戶(hù)名和密碼(這里默認(rèn)用戶(hù)名:admin,密碼:Harbor12345)。
登錄如果有問(wèn)題,可以執(zhí)行如下命令嘗試,或者重啟機(jī)器。
docker-compose down -v # 需要在 harbor 解壓包的目錄下執(zhí)行 docker-compose up -d
(2)登錄 Harbor UI 界面
登錄 Harbor UI 界面后,點(diǎn)擊 項(xiàng)目 -> library -> 推送鏡像,如下所示。

可以看到兩條命令,第一個(gè)命令就是推送到 library 項(xiàng)目下的鏡像需要打 TAG 的命令,第二條命令是推送到 library 項(xiàng)目下鏡像的推送命令。
(3)上傳鏡像
執(zhí)行 docker tag 和 docker push 命令,將鏡像上傳到 Harbor 中,如下所示。
[root@k8s-master imagesJar]# docker tag test/demo:1.2.0 192.168.231.152/library/test:1.9.0 [root@k8s-master imagesJar]# docker push 192.168.231.152/library/test:1.9.0 The push refers to a repository [192.168.231.152/library/test] 0931afb63541: Mounted from library/demo 0a8cde955e2b: Mounted from library/demo 1aaddf64804f: Mounted from library/demo 990c5138f5d1: Mounted from library/demo 5c384ea5f752: Mounted from library/demo 293d5db30c9f: Mounted from library/demo 03127cdb479b: Mounted from library/demo 9c742cd6c7a5: Mounted from library/demo 1.9.0: digest: sha256:f864fb61dc16e5df453fcb6697418d0229871c6bb584cccdfd8662b1fd06c335 size: 2001 [root@k8s-master imagesJar]#
在 Harbor UI 界面中可以看到對(duì)應(yīng)的鏡像。
3.3 下載鏡像
執(zhí)行如下命令拉取鏡像。
[root@k8s-master imagesJar]# docker pull 192.168.231.152/library/demo:1.8.0 Trying to pull repository 192.168.231.152/library/demo ... 1.8.0: Pulling from 192.168.231.152/library/demo Digest: sha256:f864fb61dc16e5df453fcb6697418d0229871c6bb584cccdfd8662b1fd06c335 Status: Image is up to date for 192.168.231.152/library/demo:1.8.0 [root@k8s-master imagesJar]#
參考鏈接:
https://www.runoob.com/docker/docker-push-command.html
https://www.cnblogs.com/pzk7788/p/10180919.html
Harbor私有鏡像倉(cāng)庫(kù)離線部署-harbor 2.5.3_harbor離線部署_渡渡甲的博客-CSDN博客
push到harbor的注意事項(xiàng)_error parsing http 405 response body: invalid char_阿白,的博客-CSDN博客
https://www.cnblogs.com/anxminise/p/9764221.html
到此這篇關(guān)于Docker私有倉(cāng)庫(kù)harbor的搭建步驟的文章就介紹到這了,更多相關(guān)Docker harbor搭建內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- docker使用dockercompose編排一個(gè)Hadoop集群方式
- Docker+DockerCompose封裝web應(yīng)用的方法步驟
- 使用dockercompose搭建springboot-mysql-nginx應(yīng)用
- docker的harbor倉(cāng)庫(kù)登錄問(wèn)題小結(jié)
- docker客戶(hù)端訪問(wèn)harbor及安裝配置更新
- Docker私有倉(cāng)庫(kù)Harbor介紹和部署方法詳解
- Docker鏡像構(gòu)建_Docker?Compose編排實(shí)踐_Docker?Harbor倉(cāng)庫(kù)的集成
相關(guān)文章
IDEA集成Docker實(shí)現(xiàn)一鍵部署全過(guò)程
本文詳細(xì)介紹了如何在IntelliJ IDEA中集成Docker并實(shí)現(xiàn)一鍵部署代碼的步驟,包括安裝Docker、配置服務(wù)器、IDEA配置、添加Dockerfile、運(yùn)行配置以及一鍵部署2024-11-11
Docker安裝RabbitMQ后訪問(wèn)報(bào)錯(cuò)的最佳解決方案
這篇文章主要介紹了Docker安裝RabbitMQ后訪問(wèn)報(bào)錯(cuò)的最佳解決方案,錯(cuò)誤通常是由于RabbitMQ的安全配置導(dǎo)致的,RabbitMQ默認(rèn)配置允許的用戶(hù)僅能通過(guò)localhost訪問(wèn),文中通過(guò)圖文講解的非常詳細(xì),需要的朋友可以參考下2025-01-01
如何解決docker容器訪問(wèn)不了外部網(wǎng)絡(luò)問(wèn)題
介紹了Docker?bridge網(wǎng)絡(luò)的工作原理,包括虛擬網(wǎng)橋的創(chuàng)建、容器的IP地址分配、IP轉(zhuǎn)發(fā)的作用以及NAT的配置,通過(guò)配置IP轉(zhuǎn)發(fā)和NAT規(guī)則,Docker能夠?qū)崿F(xiàn)容器與外部網(wǎng)絡(luò)之間的通信,文章還提供了解決某個(gè)具體問(wèn)題的步驟2024-11-11
使用Docker部署Nginx+Flask+Mongo的應(yīng)用
這篇文章主要介紹了使用Docker部署Nginx+Flask+Mongo的應(yīng)用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-03-03
Docker?磁盤(pán)占用分析和清理方法示例小結(jié)
本文介紹Docker磁盤(pán)占用分析與清理方法,涵蓋鏡像、容器、卷及構(gòu)建緩存的資源排查,提供清理未使用資源的命令及選項(xiàng),如docker system prune和docker image prune,并解釋?xiě)铱甄R像的產(chǎn)生原因及處理技巧,感興趣的朋友一起看看吧2025-07-07
docker容器間跨宿主機(jī)通信-基于overlay的實(shí)現(xiàn)方法
這篇文章主要介紹了docker容器間跨宿主機(jī)通信-基于overlay的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02
docker部署fastapi的實(shí)現(xiàn)步驟
本文主要介紹了docker部署fastapi的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03

