安装Harbor镜像仓库
安装docker
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
下载harbor安装包
# 下载Docker Harbor安装包
wget https://github.com/goharbor/harbor/releases/download/v2.12.0/harbor-offline-installer-v2.12.0.tgz
# 解压安装包
[root@chenby ~]# tar xvf harbor-offline-installer-v2.12.0.tgz -C /usr/local/
harbor/harbor.v2.12.0.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl
[root@chenby ~]# cd /usr/local/harbor/
创建证书
# 我用的是免费证书 Let's Encrypt 泛域名证书申请
https://www.oiox.cn/index.php/archives/139/
配置harbor服务
# 配置harbor文件
[root@chenby harbor]# cp harbor.yml.tmpl harbor.yml
[root@chenby harbor]# vim harbor.yml
[root@chenby harbor]# cat harbor.yml | grep -v '^#' | grep -v '^$' | grep -v ' #'
hostname: z.oiox.cn
http:
port: 18081
https:
port: 18082
certificate: /ssl/cert.pem
private_key: /ssl/cert.key
harbor_admin_password: Cby123..
database:
password: root123
max_idle_conns: 100
max_open_conns: 900
conn_max_lifetime: 5m
conn_max_idle_time: 0
data_volume: /data
trivy:
ignore_unfixed: false
skip_update: false
skip_java_db_update: false
offline_scan: false
security_check: vuln
insecure: false
timeout: 5m0s
jobservice:
max_job_workers: 10
job_loggers:
- STD_OUTPUT
- FILE
logger_sweeper_duration: 1 #days
notification:
webhook_job_max_retry: 3
webhook_job_http_client_timeout: 3 #seconds
log:
level: info
local:
rotate_count: 50
rotate_size: 200M
location: /var/log/harbor
_version: 2.12.0
proxy:
http_proxy:
https_proxy:
no_proxy:
components:
- core
- jobservice
- trivy
upload_purging:
enabled: true
age: 168h
interval: 24h
dryrun: false
cache:
enabled: false
expire_hours: 24
[root@chenby harbor]#
安装harbor
# 进行安装
[root@chenby harbor]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 27.3.1
[Step 1]: checking docker-compose is installed ...
Note: Docker Compose version v2.29.7
[Step 2]: loading Harbor images ...
910db7c25623: Loading layer [==================================================>] 40.51MB/40.51MB
c8cd0a1f5b0b: Loading layer [==================================================>] 107.6MB/107.6MB
15d8ff051c07: Loading layer [==================================================>] 46.48MB/46.48MB
d197fd97c185: Loading layer [==================================================>] 13.77MB/13.77MB
d88ec2163d81: Loading layer [==================================================>] 66.05kB/66.05kB
e63d6d00357d: Loading layer [==================================================>] 2.56kB/2.56kB
b802bc40d720: Loading layer [==================================================>] 1.536kB/1.536kB
8225980335b5: Loading layer [==================================================>] 12.29kB/12.29kB
3175598f5b32: Loading layer [==================================================>] 2.746MB/2.746MB
ef05ddf12dfe: Loading layer [==================================================>] 525.3kB/525.3kB
Loaded image: goharbor/prepare:v2.12.0
32cd15a4ebdd: Loading layer [==================================================>] 16.27MB/16.27MB
0dd22cb0da1b: Loading layer [==================================================>] 190.2MB/190.2MB
ac30f78bb9c1: Loading layer [==================================================>] 26.08MB/26.08MB
527459edc5ee: Loading layer [==================================================>] 18.6MB/18.6MB
0fe3e34fe571: Loading layer [==================================================>] 5.12kB/5.12kB
eb0883932a36: Loading layer [==================================================>] 6.144kB/6.144kB
49b31970580b: Loading layer [==================================================>] 3.072kB/3.072kB
478aa400459f: Loading layer [==================================================>] 2.048kB/2.048kB
c39207896960: Loading layer [==================================================>] 2.56kB/2.56kB
e3a89007fad0: Loading layer [==================================================>] 7.68kB/7.68kB
Loaded image: goharbor/harbor-db:v2.12.0
eb105901976e: Loading layer [==================================================>] 11.57MB/11.57MB
4c386227a4e4: Loading layer [==================================================>] 3.584kB/3.584kB
4f442ab7cc4c: Loading layer [==================================================>] 2.56kB/2.56kB
2fa6704b1ae6: Loading layer [==================================================>] 59.63MB/59.63MB
65c014dfa82d: Loading layer [==================================================>] 60.42MB/60.42MB
Loaded image: goharbor/harbor-jobservice:v2.12.0
4cab912836a2: Loading layer [==================================================>] 8.614MB/8.614MB
247df5f5c893: Loading layer [==================================================>] 4.096kB/4.096kB
9ee7df405168: Loading layer [==================================================>] 18.13MB/18.13MB
d628a65e4634: Loading layer [==================================================>] 3.072kB/3.072kB
1759c807e026: Loading layer [==================================================>] 36.96MB/36.96MB
bee402e81ccd: Loading layer [==================================================>] 55.88MB/55.88MB
Loaded image: goharbor/harbor-registryctl:v2.12.0
afc604caf53d: Loading layer [==================================================>] 11.57MB/11.57MB
f9eb13f95461: Loading layer [==================================================>] 37.01MB/37.01MB
e98d25e4c661: Loading layer [==================================================>] 4.608kB/4.608kB
8dd3c4f177e1: Loading layer [==================================================>] 37.8MB/37.8MB
Loaded image: goharbor/harbor-exporter:v2.12.0
31e9c30e4a21: Loading layer [==================================================>] 16.27MB/16.27MB
bfcf2dfddce8: Loading layer [==================================================>] 125.1MB/125.1MB
1660b90f9dc7: Loading layer [==================================================>] 3.072kB/3.072kB
93c9be43608f: Loading layer [==================================================>] 59.9kB/59.9kB
d69d92256927: Loading layer [==================================================>] 61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.12.0
769c4aa8c0a4: Loading layer [==================================================>] 8.614MB/8.614MB
9cd556727275: Loading layer [==================================================>] 4.096kB/4.096kB
0edc0bc0fa32: Loading layer [==================================================>] 3.072kB/3.072kB
30823cd3e953: Loading layer [==================================================>] 18.13MB/18.13MB
31ffd46d4827: Loading layer [==================================================>] 18.92MB/18.92MB
Loaded image: goharbor/registry-photon:v2.12.0
8f8c2600e204: Loading layer [==================================================>] 130.1MB/130.1MB
676f1d057a8c: Loading layer [==================================================>] 6.731MB/6.731MB
71425f9960bc: Loading layer [==================================================>] 252.9kB/252.9kB
8ce274b4eb81: Loading layer [==================================================>] 1.497MB/1.497MB
Loaded image: goharbor/harbor-portal:v2.12.0
4ed6c9567d72: Loading layer [==================================================>] 11.57MB/11.57MB
68c5cae40c58: Loading layer [==================================================>] 3.584kB/3.584kB
a29956692eb6: Loading layer [==================================================>] 2.56kB/2.56kB
d4eac84f665a: Loading layer [==================================================>] 70.77MB/70.77MB
c2d39ec31cb3: Loading layer [==================================================>] 5.632kB/5.632kB
81df0033286e: Loading layer [==================================================>] 126.5kB/126.5kB
847040daf450: Loading layer [==================================================>] 201.7kB/201.7kB
cba56604cbfc: Loading layer [==================================================>] 71.89MB/71.89MB
6d8fda582e88: Loading layer [==================================================>] 2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v2.12.0
8dd98fe70bfa: Loading layer [==================================================>] 139.8MB/139.8MB
c0691b0983da: Loading layer [==================================================>] 3.584kB/3.584kB
a205646db971: Loading layer [==================================================>] 3.072kB/3.072kB
36bea9385de7: Loading layer [==================================================>] 2.56kB/2.56kB
624bbccc716a: Loading layer [==================================================>] 3.072kB/3.072kB
cee989d2b0b0: Loading layer [==================================================>] 3.584kB/3.584kB
73035228c2e1: Loading layer [==================================================>] 20.48kB/20.48kB
Loaded image: goharbor/harbor-log:v2.12.0
d397faf073f1: Loading layer [==================================================>] 130.1MB/130.1MB
Loaded image: goharbor/nginx-photon:v2.12.0
3e1f1096c4bf: Loading layer [==================================================>] 9.106MB/9.106MB
9cc192b1539e: Loading layer [==================================================>] 4.096kB/4.096kB
a4448f8ca935: Loading layer [==================================================>] 3.072kB/3.072kB
38c665e4daa5: Loading layer [==================================================>] 133.8MB/133.8MB
867c3a3ec63e: Loading layer [==================================================>] 15.55MB/15.55MB
e04b98ae7085: Loading layer [==================================================>] 150.1MB/150.1MB
Loaded image: goharbor/trivy-adapter-photon:v2.12.0
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /usr/local/harbor
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
Note: stopping existing Harbor instance ...
[Step 5]: starting Harbor ...
[+] Running 10/10
✔ Network harbor_harbor Created 0.2s
✔ Container harbor-log Started 0.4s
✔ Container harbor-db Started 0.6s
✔ Container redis Started 0.7s
✔ Container registryctl Started 0.7s
✔ Container harbor-portal Started 0.7s
✔ Container registry Started 0.6s
✔ Container harbor-core Started 0.8s
✔ Container nginx Started 1.1s
✔ Container harbor-jobservice Started 1.0s
✔ ----Harbor has been installed and started successfully.----
[root@chenby harbor]#
配置解析和docker
# FQDN解析
cat >> /etc/hosts <<EOF
192.168.1.120 z.oiox.cn
EOF
# 例如docker的配置
# 如果没有正式的域名以及ssl证书就需要配置 insecure-registries 参数
[root@chenby ~]# cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"insecure-registries": ["z.oiox.cn:18082"],
"registry-mirrors": [
"https://xxxxx.mirror.aliyuncs.com"
],
"max-concurrent-downloads": 10,
"log-driver": "json-file",
"log-level": "warn",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"data-root": "/var/lib/docker"
}
EOF
# 重新启动docker
[root@chenby ~]# systemctl restart docker && systemctl status docker -l
测试使用
# 登陆
[root@chenby ~]# docker login z.oiox.cn:18082
Username: admin
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/#credential-stores
Login Succeeded
[root@chenby ~]#
# 构建镜像
[root@chenby ~]# cat > Dockerfile <<EOF
FROM nginx
RUN echo '这是一个本地构建的nginx镜像,第一版' > /usr/share/nginx/html/index.html
EOF
docker build -t z.oiox.cn:18082/library/cby:v1 .
[root@chenby ~]# cat > Dockerfile <<EOF
FROM nginx
RUN echo '这是一个本地构建的nginx镜像,第二版' > /usr/share/nginx/html/index.html
EOF
docker build -t z.oiox.cn:18082/library/cby:v2 .
docker push z.oiox.cn:18082/library/cby:v1
docker push z.oiox.cn:18082/library/cby:v2
docker rmi z.oiox.cn:18082/library/cby:v1
docker rmi z.oiox.cn:18082/library/cby:v2
docker pull z.oiox.cn:18082/library/cby:v1
docker pull z.oiox.cn:18082/library/cby:v2
标签:kB,layer,Loading,harbor,MB,Harbor,仓库,镜像,docker From: https://www.cnblogs.com/chenby/p/18550397关于
https://www.oiox.cn/index.php/start-page.html
CSDN、GitHub、51CTO、知乎、开源中国、思否、掘金、简书、华为云、阿里云、腾讯云、哔哩哔哩、今日头条、新浪微博、个人博客
全网可搜《小陈运维》
文章主要发布于微信公众号