安装Harbor镜像仓库

本文涉及的产品
容器镜像服务 ACR,镜像仓库100个 不限时长
简介: 本文介绍了如何在Linux系统上安装和配置Harbor镜像仓库。首先通过阿里云镜像源安装Docker,然后下载并解压Harbor离线安装包。配置Harbor服务的相关参数。最后,通过运行安装脚本完成Harbor的安装,并进行基本的测试,包括登录、构建和推送Docker镜像。文章还提供了相关资源链接,方便读者进一步了解和学习。

安装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

关于

https://www.oiox.cn/

https://www.oiox.cn/index.php/start-page.html

CSDN、GitHub、51CTO、知乎、开源中国、思否、掘金、简书、华为云、阿里云、腾讯云、哔哩哔哩、今日头条、新浪微博、个人博客

全网可搜《小陈运维》

文章主要发布于微信公众号

相关实践学习
通过容器镜像仓库与容器服务快速部署spring-hello应用
本教程主要讲述如何将本地Java代码程序上传并在云端以容器化的构建、传输和运行。
Kubernetes极速入门
Kubernetes(K8S)是Google在2014年发布的一个开源项目,用于自动化容器化应用程序的部署、扩展和管理。Kubernetes通常结合docker容器工作,并且整合多个运行着docker容器的主机集群。 本课程从Kubernetes的简介、功能、架构,集群的概念、工具及部署等各个方面进行了详细的讲解及展示,通过对本课程的学习,可以对Kubernetes有一个较为全面的认识,并初步掌握Kubernetes相关的安装部署及使用技巧。本课程由黑马程序员提供。 &nbsp; 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情:&nbsp;https://www.aliyun.com/product/kubernetes
相关文章
|
2月前
|
JavaScript 前端开发 Docker
前端的全栈之路Meteor篇(一):开发环境的搭建 -全局安装或使用容器镜像
本文介绍了如何搭建 Meteor 开发环境,包括全局安装 Meteor 工具和使用 Docker 镜像两种方法,以及创建和运行一个简单的 Meteor 项目的基本步骤。 Meteor 是一个全栈 JavaScript 框架,适用于构建实时 Web 应用程序。文章还提供了遇到问题时的解决建议和调试技巧。
|
2月前
|
Kubernetes Ubuntu NoSQL
harbor镜像仓库自建
harbor镜像仓库自建
|
5月前
|
数据可视化 Linux 数据安全/隐私保护
Harbor私有镜像仓库搭建
Harbor私有镜像仓库搭建
69 3
|
4月前
|
Docker 容器
docker: 搭建 harbor 镜像仓库
docker: 搭建 harbor 镜像仓库
|
7月前
|
存储 API 数据安全/隐私保护
企业级Docker镜像仓库Harbor部署与使用
企业级Docker镜像仓库Harbor部署与使用
|
7月前
|
存储 安全 数据库
搭建Harbor镜像仓库
搭建Harbor镜像仓库
335 2
|
7月前
|
JavaScript Devops Java
DevOps搭建(一)-安装Harbor镜像仓库详细步骤
DevOps搭建(一)-安装Harbor镜像仓库详细步骤
110 0
|
7月前
|
Shell Linux 开发工具
搭建自己的Docker Harbor镜像仓库(2)-- 使用篇
搭建自己的Docker Harbor镜像仓库(2)-- 使用篇
192 1
|
7月前
|
Docker 容器
搭建自己的Docker Harbor镜像仓库(1)--- 安装篇
搭建自己的Docker Harbor镜像仓库(1)--- 安装篇
195 1
|
2月前
|
Linux 应用服务中间件 Shell
docker学习--docker容器镜像常用命令大全(简)
本文档详细介绍了Docker中的镜像命令与容器管理命令。镜像命令部分涵盖了镜像搜索、下载、上传等操作;容器管理命令则包括了容器的创建、启动、停止、删除及日志查看等功能。通过具体示例,帮助用户更好地理解和使用Docker相关命令。
179 0