1. harbor簡介:
- Harbor是一個用于存儲和分發(fā)Docker鏡像的企業(yè)級Registry服務器,通過添加一些企業(yè)必需的功能特性,例如安全、標識和管理等,擴展了開源Docker Distribution。
- 作為一個企業(yè)級私有Registry服務器,Harbor提供了更好的性能和安全。提升用戶使用Registry構(gòu)建和運行環(huán)境傳輸鏡像的效率。Harbor支持安裝在多個Registry節(jié)點的鏡像資源復制,鏡像全部保存在私有Registry中,確保數(shù)據(jù)和知識產(chǎn)權(quán)在公司內(nèi)部網(wǎng)絡中管控。另外,Harbor也提供了高級的安全特性,諸如用戶管理,訪問控制和活動審計等。
2. harbor部署:
資源 | 最低 | 推薦 |
---|---|---|
CPU | 2cpu | 4cpu |
Mem | 4GB | 8GB |
Disk | 40GB | 160GB |
- Harbor倉庫部署兩種方式,一種是off-line ,一種是on-line,即離線和在線安裝,此處選擇離線安裝:
2.1. 安裝Docker-Compose快速編排工具
//下載Docker compose腳本
[root@localhost ~]# curl -SL https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
//添加腳本x權(quán)限
chmod +x /usr/local/bin/docker-compose
//查看版本信息
[root@localhost ~]# docker-compose --version
Docker Compose version v2.17.2
2.2. 下載Harbor并且解壓
//下載harbor離線安裝包
wget -c https://github.com/goharbor/harbor/releases/download/v2.8.1/harbor-offline-installer-v2.8.1.tgz
//解壓
tar -xf harbor-offline-installer-v2.8.1.tgz
2.3. 修改Habor配置文件harbor.cfg
root@harbor ~]# cd harbor/
[root@harbor harbor]# ls
common.sh harbor.v2.8.1.tar.gz harbor.yml.tmpl install.sh LICENSE prepare
//備份配置文件并進行配置
[root@harbor harbor]# cp harbor.yml.tmpl harbor.yml
//修改配置文件中hostname內(nèi)容
[root@harbor harbor]# vim harbor.yml
....
hostname: 192.168.2.50 #修改為當前主機的IP或域名
# http related config
http:
port: 80
#https: #注釋掉https服務
# port: 443
# certificate: /your/certificate/path
# private_key: /your/private/key/path
# internal_tls:
# enabled: true
# dir: /etc/harbor/tls/internal
harbor_admin_password: Harbor12345 --指定密碼
2.4. 安裝Harbor
//執(zhí)行安裝腳本
[root@harbor harbor]# ./install.sh
[root@harbor harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
00f23b78bc06 goharbor/harbor-jobservice:v2.8.1 "/harbor/entrypoint.…" 6 minutes ago Up 6 minutes (healthy) harbor-jobservice
6ffdec9ca084 goharbor/nginx-photon:v2.8.1 "nginx -g 'daemon of…" 6 minutes ago Up 6 minutes (healthy) 0.0.0.0:80->8080/tcp, :::80->8080/tcp nginx
0b7c8c12a91a goharbor/harbor-core:v2.8.1 "/harbor/entrypoint.…" 6 minutes ago Up 6 minutes (healthy) harbor-core
198b58f0dd3a goharbor/harbor-registryctl:v2.8.1 "/home/harbor/start.…" 6 minutes ago Up 6 minutes (healthy) registryctl
f680b8bd36fc goharbor/harbor-db:v2.8.1 "/docker-entrypoint.…" 6 minutes ago Up 6 minutes (healthy) harbor-db
cef2df05b319 goharbor/redis-photon:v2.8.1 "redis-server /etc/r…" 6 minutes ago Up 6 minutes (healthy) redis
f41401422a96 goharbor/registry-photon:v2.8.1 "/home/harbor/entryp…" 6 minutes ago Up 6 minutes (healthy) registry
717da9c60854 goharbor/harbor-portal:v2.8.1 "nginx -g 'daemon of…" 6 minutes ago Up 6 minutes (healthy) harbor-portal
764e82d18fe1 goharbor/harbor-log:v2.8.1 "/bin/sh -c /usr/loc…" 6 minutes ago Up 6 minutes (healthy) 127.0.0.1:1514->10514/tcp harbor-log
//使用docker-compose管理harbor啟動和停止服務(需要進到harbor目錄中)
//關(guān)閉harbor服務
[root@harbor harbor]# docker-compose stop
[+] Running 9/9
? Container nginx Stopped 0.2s
? Container registryctl Stopped 10.1s
? Container harbor-jobservice Stopped 0.2s
? Container harbor-portal Stopped 0.2s
? Container harbor-core Stopped 0.2s
? Container harbor-db Stopped 0.2s
? Container registry Stopped 0.1s
? Container redis Stopped 0.3s
? Container harbor-log Stopped 10.1s
//啟動harbor服務
[root@harbor harbor]# docker-compose start
[+] Running 9/9
? Container harbor-log Started 0.2s
? Container harbor-portal Started 1.3s
? Container harbor-db Started 1.1s
? Container redis Started 1.3s
? Container registry Started 1.4s
? Container registryctl Started 0.8s
? Container harbor-core Started 0.3s
? Container harbor-jobservice Started 0.5s
? Container nginx Started 0.6s
//配置harbor服務開機自啟
[root@harbor harbor]# vim startall.sh #寫一個開啟自動啟動的腳本
#!/bin/bash
cd /usr/local/harbor
docker-compose stop && docker-compose start
[root@harbor harbor]# chmod +x startall.sh #給腳本執(zhí)行權(quán)限
[root@harbor harbor]# chmod +x /etc/rc.d/rc.local #rc.local是系統(tǒng)啟動之后最后一個執(zhí)行的文件
[root@harbor harbor]# vim /etc/rc.d/rc.local #添加以下內(nèi)容就可以開機自啟了
...
/bin/bash /root/harbor/startall.sh
...
2.5. 登錄harbor的web平臺
- 默認用戶名:admin,默認密碼:Harbor12345
2.6. 登錄成功界面
2.7. 創(chuàng)建用戶
- 系統(tǒng)管理—用戶管理—創(chuàng)建用戶
2.8. 創(chuàng)建用戶成功,并設置為管理員
文章來源:http://www.zghlxwxcb.cn/news/detail-666515.html
2.9. 點擊項目,查看推送命令
文章來源地址http://www.zghlxwxcb.cn/news/detail-666515.html
2.10. 推送鏡像至harbor
- 登錄倉庫
[root@harbor harbor]# docker login 192.168.2.50
Username: ys
Password:
Error response from daemon: Get "https://192.168.2.50/v2/": dial tcp 192.168.2.50:443: connect: connection refused
- 解決登錄失敗方法如下:
- 默認訪問Docker倉庫使用443端口,要修改為80端口倉庫地址
[root@harbor harbor]# vim /etc/docker/daemon.json
{
"insecure-registries":["192.168.2.50"]
}
//重啟harbor服務:
[root@harbor harbor]# docker-compose stop && docker-compose start
//再次登錄harbor:
[root@harbor harbor]# docker login 192.168.2.50
Username: ys
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
- 下載鏡像并修改tag
[root@harbor harbor]# docker pull nginx
[root@harbor harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f9c14fe76d50 6 days ago 143MB
....
//在項目中標記鏡像
[root@harbor harbor]# docker tag nginx:latest 192.168.2.50/library/nginx:v1
[root@harbor harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.2.50/library/nginx v1 f9c14fe76d50 6 days ago 143MB
nginx latest f9c14fe76d50 6 days ago 143MB
...
- 推送鏡像到library項目
[root@harbor harbor]# docker push 192.168.2.50/library/nginx:v1
The push refers to repository [192.168.2.50/library/nginx]
4fd834341303: Pushed
5e099cf3f3c8: Pushed
7daac92f43be: Pushed
e60266289ce4: Pushed
4b8862fe7056: Pushed
8cbe4b54fa88: Pushed
v1: digest: sha256:6b06964cdbbc517102ce5e0cef95152f3c6a7ef703e4057cb574539de91f72e6 size: 1571
- 查看是否推送成功
2.11. 拉取鏡像
- 刪除原來的鏡像
[root@harbor harbor]# docker rmi 192.168.2.50/library/nginx:v1
[root@harbor harbor]# docker rmi nginx:latest
[root@harbor harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
goharbor/harbor-exporter v2.8.1 bfbbb56f0c0e 3 weeks ago 97.9MB
goharbor/redis-photon v2.8.1 cb8b735b33ba 3 weeks ago 128MB
goharbor/trivy-adapter-photon v2.8.1 5314d0e3feb2 3 weeks ago 454MB
goharbor/notary-server-photon v2.8.1 d11f3ca7e07e 3 weeks ago 113MB
goharbor/notary-signer-photon v2.8.1 e97556d5f939 3 weeks ago 111MB
goharbor/harbor-registryctl v2.8.1 c141d82ffd0a 3 weeks ago 141MB
goharbor/registry-photon v2.8.1 c125efcb6c2a 3 weeks ago 79.1MB
goharbor/nginx-photon v2.8.1 cea1bb2450ee 3 weeks ago 127MB
goharbor/harbor-log v2.8.1 145a69b937ca 3 weeks ago 134MB
goharbor/harbor-jobservice v2.8.1 977ee6bff288 3 weeks ago 141MB
goharbor/harbor-core v2.8.1 075ed731ac18 3 weeks ago 165MB
goharbor/harbor-portal v2.8.1 6c2b21221aca 3 weeks ago 134MB
goharbor/harbor-db v2.8.1 01ca249e7dc2 3 weeks ago 174MB
goharbor/prepare v2.8.1 4f83854677d4 3 weeks ago 155MB
- 拉取鏡像
[root@harbor harbor]# docker pull 192.168.2.50/library/nginx:v1
[root@harbor harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.2.50/library/nginx v1 f9c14fe76d50 6 days ago 143MB
goharbor/harbor-exporter v2.8.1 bfbbb56f0c0e 3 weeks ago 97.9MB
goharbor/redis-photon v2.8.1 cb8b735b33ba 3 weeks ago 128MB
goharbor/trivy-adapter-photon v2.8.1 5314d0e3feb2 3 weeks ago 454MB
goharbor/notary-server-photon v2.8.1 d11f3ca7e07e 3 weeks ago 113MB
goharbor/notary-signer-photon v2.8.1 e97556d5f939 3 weeks ago 111MB
goharbor/harbor-registryctl v2.8.1 c141d82ffd0a 3 weeks ago 141MB
goharbor/registry-photon v2.8.1 c125efcb6c2a 3 weeks ago 79.1MB
goharbor/nginx-photon v2.8.1 cea1bb2450ee 3 weeks ago 127MB
goharbor/harbor-log v2.8.1 145a69b937ca 3 weeks ago 134MB
goharbor/harbor-jobservice v2.8.1 977ee6bff288 3 weeks ago 141MB
goharbor/harbor-core v2.8.1 075ed731ac18 3 weeks ago 165MB
goharbor/harbor-portal v2.8.1 6c2b21221aca 3 weeks ago 134MB
goharbor/harbor-db v2.8.1 01ca249e7dc2 3 weeks ago 174MB
goharbor/prepare v2.8.1 4f83854677d4 3 weeks ago 155MB
到了這里,關(guān)于docker私有倉庫harbor部署的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!