docker方式部署镜像管理平台harbor

参考:

一. 下载安装包后解压 加载docker镜像

NOTE: 此处解压到opt目录

1.下载解压

1
2
3
4
# 下载
wget https://github.com/goharbor/harbor/releases/download/v2.9.1/harbor-offline-installer-v2.9.1.tgz
# 解压
cd /opt && tar -xvzf harbor-offline-installer-v2.9.1.tgz

4.加载镜像

1
2
3
4
5
6
# cd到项目目录
cd /opt/harbor
# 加载镜像
docker load -i harbor.v2.9.1.tar.gz
# 查看生成的镜像
docker images

image-20231110220747727

image-20231110220939874

二. 配置及安装

1.配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 配置harbor.yml
cd harbor && cp harbor.yml.tmpl harbor.yml
[root@localhost harbor]# ls
common.sh harbor.v1.10.10.tar.gz harbor.yml harbor.yml.tmpl install.sh LICENSE prepare
# 配置harbor.yml
vim harbor.yml
# 修改如下两部分即可 设置本机IP
hostname: 10.0.0.10
# 设置 https https related config
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /opt/harbor/keys/ssl.crt
private_key: /opt/harbor/keys/ssl_nopass.key

image-20231110232726417

2.安装 执行./prepare && ./install.sh命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# cd到项目目录
cd /opt/harbor
# 执行prepare脚本
./prepare
// 返回
prepare base dir is set to /opt/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
# 执行install.sh脚本
cd /opt/harbor && ./install.sh
// 返回
.....略
[+] Running 10/10
✔ Network harbor_harbor Created 0.1s
✔ Container harbor-log Started 3.0s
✔ Container harbor-portal Started 6.7s
✔ Container registryctl Started 7.5s
✔ Container harbor-db Started 3.6s
✔ Container redis Started 6.6s
✔ Container registry Started 5.4s
✔ Container harbor-core Started 8.5s
✔ Container nginx Started 10.5s
✔ Container harbor-jobservice Started 9.7s
✔ ----Harbor has been installed and started successfully.----
# 查看容器
cd /opt/harbor && docker-compose ps

image-20231110222053846


image-20231110224332597

三. 测试使用harbor

1.编辑 /etc/docker/daemon.json,并重启docker

1
2
3
4
5
6
7
8
9
10
11
12
# 编辑配置
vim /etc/docker/daemon.json
# 添加如下配置
{ "registry-mirrors": ["https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com"],
"insecure-registries": ["10.0.0.10","harbor"]
# 表示我们内网访问harbor的时候走的是http,192.168.5.135是安装harbor机器的ip
}
# 重启docker
systemctl daemon-reload && systemctl restart docker
systemctl status docker
# 显示如下,则说明启动成功了
Active: active (running) since 二 2023-06-20 00:07:12 CST; 10h ago

2. 设置hosts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 设置hosts
vim /etc/hosts
# 末尾添加 10.0.0.10 harbor

127.0.0.1 localhost
127.0.1.1 zznn

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.0.0.10 harbor

3.修改镜像tag

1
2
3
4
5
# 修改镜像tag
docker tag b5b6bcf0bafe 10.0.0.10/library/chatgpt-web:latest
# 登录 Harbor
docker login 10.0.0.10
# 推送镜像到 Harbor

4.推送镜像到harbor仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 推送
docker push 10.0.0.10/library/chatgpt-web:latest
// 返回
The push refers to repository [10.0.0.10/library/chatgpt-web]
e5292cf7dd7e: Pushed
bc6df8c654aa: Pushed
90a441cbe44e: Pushed
32f853371e04: Pushed
1351bec6bffb: Pushed
6b792328b3a0: Pushed
221818d7d1a0: Pushed
79575536fd86: Pushed
a9aa4cfc7b2d: Pushed
0d5e1f8c333d: Pushed
25156ca953a7: Pushed
cc2447e1835a: Pushed
latest: digest: sha256:9e54ed5894e08edb1f23c904f00f99bb3267f3d4fd2537899dedb47118b62c07 size: 2831

image-20231110232222651

推送成功:

image-20231110232400336

四. 效果(访问:http:10.0.0.10密码admin/Harbor12345

image-20231110232431107


image-20231110232442911

教程结束。