?? 作者:Linux猿
?? 簡(jiǎn)介:CSDN博客專家??,華為云享專家??,Linux、C/C++、云計(jì)算、物聯(lián)網(wǎng)、面試、刷題、算法盡管咨詢我,關(guān)注我,有問(wèn)題私聊!
?? 歡迎小伙伴們點(diǎn)贊??、收藏?、留言??
目錄
一、實(shí)驗(yàn)環(huán)境
二、安裝 harbor?
2.1 安裝 docker 和 docker-compose
2.2 安裝 harbor
2.3 登錄 harbor UI 界面
三、測(cè)試上傳和下載鏡像
3.1 docker 常用命令
3.2 上傳鏡像
3.3 下載鏡像
本篇文章主要介紹 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 界面,如下所示。
用戶名和密碼如下所示。
用戶名: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,然后輸入用戶名和密碼(這里默認(rèn)用戶名: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博客
Harbor安裝小坑Please set hostname and other necessary attributes in harbor.cfg first._please do not set --with-chartmuseum, as chartmusu_流年 Narcissus yu的博客-CSDN博客?報(bào)錯(cuò):ERROR: for nginx Cannot start service proxy;for proxy Cannot start service proxy;......_這閨女長(zhǎng)得真俊啊的博客-CSDN博客
push到harbor的注意事項(xiàng)_error parsing http 405 response body: invalid char_阿白,的博客-CSDN博客
https://www.cnblogs.com/anxminise/p/9764221.html
?? 感覺(jué)有幫助記得「一鍵三連」支持下哦!有問(wèn)題可在評(píng)論區(qū)留言??,感謝大家的一路支持!??猿哥將持續(xù)輸出「優(yōu)質(zhì)文章」回饋大家!????????????????文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-567276.html
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-567276.html
到了這里,關(guān)于Docker 私有倉(cāng)庫(kù) harbor 搭建的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!