私有的docker私有镜像站仓库harbor

简介: 私有的docker私有镜像站仓库harbor

需要准备的文件
harbor 方便在企业内部实现私有的容器镜像仓库,方便镜像的分发。

需要准备3个文件
docker compose 文件
harbor 文件
TLS 证书文件
docker hub 在部署当中需要 docker compose 来做容器的编排部署。

部署 harbor 有两种模式,一种是在线模式,一种是离线模式,在线模式由于受到网络环境的影响部署的时间会比较长,网络就会不稳定就会导致无法正常使用,所以一般也就推荐使用离线部署的模式,离线部署就需要用到离线的包。

在访问 harbor 的过程中,http 与 https 这两种协议都可以使用,为了安全性就要使用 SSL 证书,在 harbor 的配置文件当中都会有所涉及。

▷ 获取 docker compose 文件
对于安装 docker compose 文件的时候,CPU 建议配置到2核,内存是4G以上为满足harbor后面的增长需求。

这里我使用的 docker compose 的下载地址:

https://objects.githubusercontent.com/github-production-release-asset-2e65be/15045751/56e530c4-050d-4fb2-a8ab-b9451171b912?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241010%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241010T150425Z&X-Amz-Expires=300&X-Amz-Signature=e5fb58d7f455d5e24eb2b35b9b3d92fb667c57e0282021b25a1a994fbe0daee8&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Ddocker-compose-linux-x86_64&response-content-type=application%2Foctet-stream
[root@server bin]# pwd
/root/bin

[root@server bin]# mv docker-compose-linux-x86_64 docker-compose

[root@server bin]# chmod +x docker-compose

[root@server bin]# docker-compose version
Docker Compose version v2.29.6

▷ 获取 harbor 文件
[root@server bin]# cd /home

[root@server home]# wget https://github.com/goharbor/harbor/releases/download/v2.11.1/harbor-offline-installer-v2.11.1.tgz
--snip--
2024-10-10 23:30:00 (1.91 MB/s) - ‘harbor-offline-installer-v2.11.1.tgz’ saved [658192407/658192407]

[root@server home]# ll
total 642768
-rw-r--r--. 1 root root 658192407 Aug 21 10:27 harbor-offline-installer-v2.11.1.tgz

▷ 准备证书文件-获取TLS文件
https://www.toolhelper.cn/SSL/SSLGenerate 用于自己实验使用的证书生成网站。

这里准备的文件是 harbor-offline-installer-v2.11.1.tgz 这个文件。

此时在 /home 目录中则就有 harbor 的文件 和 证书文件 这两个文件。

[root@server home]# ll
total 642780
-rw-r--r--. 1 root root 658192407 Aug 21 10:27 harbor-offline-installer-v2.11.1.tgz
-rw-r--r--. 1 root root 5253 Oct 10 23:50 ssl_generate.zip

▶ 解压与配置文件

▷ 解压和配置准备
解压上面的两个文件

[root@server home]# tar -xzvf harbor-offline-installer-v2.11.1.tgz
harbor/harbor.v2.11.1.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl

[root@server home]# unzip ssl_generate.zip
Archive: ssl_generate.zip
inflating: generate.pfx
inflating: cert.pem
inflating: private.key
此时就有:

[root@server home]# ll
total 642788
-rw-r--r--. 1 root root 1263 Oct 10 23:36 cert.pem
-rw-r--r--. 1 root root 2620 Oct 10 23:36 generate.pfx
drwxr-xr-x. 2 root root 123 Oct 11 12:20 harbor
-rw-r--r--. 1 root root 658192407 Aug 21 10:27 harbor-offline-installer-v2.11.1.tgz
-rw-r--r--. 1 root root 1714 Oct 10 23:36 private.key
-rw-r--r--. 1 root root 5253 Oct 10 23:50 ssl_generate.zip
此时将认证文件放在 harbor 目录下:

[root@server home]# ll
total 642788
-rw-r--r--. 1 root root 1263 Oct 10 23:36 cert.pem
-rw-r--r--. 1 root root 2620 Oct 10 23:36 generate.pfx
drwxr-xr-x. 2 root root 123 Oct 11 12:20 harbor
-rw-r--r--. 1 root root 658192407 Aug 21 10:27 harbor-offline-installer-v2.11.1.tgz
drwx------. 2 hp hp 83 Aug 15 09:34 hp
-rw-r--r--. 1 root root 1714 Oct 10 23:36 private.key
-rw-r--r--. 1 root root 5253 Oct 10 23:50 ssl_generate.zip

[root@server home]# mv cert.pem generate.pfx private.key harbor
进入 harbor 目录后,找到 harbor 的配置文件,这个配置文件是 harbor.yml.tmpl 用于生效的 harbor 的配置文件是 harbor.yml。

使用 cp 既保存了先前的 harbor.yml.tmpl 也有了配置文件 harbor.yml。

[root@server home]# cd harbor/
[root@server harbor]# cp harbor.yml.tmpl harbor.yml

▷ 配置
[root@server harbor]# vim harbor.yml
--snip--
3 # The IP address or hostname to access admin UI and registry service.
4 # DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
5 hostname: reg.mydomain.com

==> 修改第5行
5 hostname: www.harborexample.com
hostname:修改成域名或者是 IP 地址,这里我使用的是 www.harborexample.com 域名。

16 # The path of cert and key files for nginx
17 certificate: /your/certificate/path
18 private_key: /your/private/key/path

==> 修改第 17-18 行
17 certificate: /home/harbor/cert.pem
18 private_key: /home/harbor/private.key

后面的 47 行默认配置了 harbor 的 admin 用户登陆的密码是 Harbor12345,datebase 的数据密码是 root123 。

47 harbor_admin_password: Harbor12345
48
49 # Harbor DB configuration
50 database:
51 # The password for the root user of Harbor DB. Change this before any production use.
52 password: root123

▶ 执行与预备安装脚本
执行预备脚本:

[root@server harbor]# ./prepare
prepare base dir is set to /home/harbor
Unable to find image 'goharbor/prepare:v2.11.1' locally
v2.11.1: Pulling from goharbor/prepare
21fde6fe7256: Pull complete
e7d411dc7b71: Pull complete
956686c6154d: Pull complete
ccc241b37d9f: Pull complete
--snip--
这会拉取镜像文件。

执行安装脚本

[root@server harbor]# ./install.sh

[Step 0]: checking if docker is installed ...
--sni--
[+] Running 10/10
✔ Network harbor_harbor Created 0.2s
✔ Container harbor-log Started 0.5s
✔ Container harbor-portal Started 1.8s
✔ Container registry Started 1.9s
✔ Container redis Started 1.4s
✔ Container harbor-db Started 1.9s
✔ Container registryctl Started 1.8s
✔ Container harbor-core Started 2.2s
✔ Container nginx Started 3.4s
✔ Container harbor-jobservice Started 2.9s
✔ ----Harbor has been installed and started successfully.----
这样 harbor 的配置与安装就算简单的完成了。

[kod.tjbxt.com)
[kod.hehuakeng.com)
[kod.gbhospital.com)
[kod.think-cg.net)
[kod.shxiduguolv.com)
[kod.dzmwood.com)
[kod.lhjdfc.com)
[kod.86tax.net)

用户名是 admin, 密码是 Harbor12345。

▶ 验证运行情况
[root@server harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5b90d66a877 goharbor/harbor-jobservice:v2.11.1 "/harbor/entrypoint.…" 6 minutes ago Up 6 minutes (healthy) harbor-jobservice
6f3cae3fd8fa goharbor/nginx-photon:v2.11.1 "nginx -g 'daemon of…" 6 minutes ago Up 6 minutes (healthy) 0.0.0.0:80->8080/tcp, [::]:80->8080/tcp, 0.0.0.0:443->8443/tcp, [::]:443->8443/tcp nginx
24b256df6c94 goharbor/harbor-core:v2.11.1 "/harbor/entrypoint.…" 6 minutes ago Up 6 minutes (healthy) harbor-core
7882833acb96 goharbor/harbor-db:v2.11.1 "/docker-entrypoint.…" 6 minutes ago Up 6 minutes (healthy) harbor-db
743eb9f226e6 goharbor/redis-photon:v2.11.1 "redis-server /etc/r…" 6 minutes ago Up 6 minutes (healthy) redis
d3045620b287 goharbor/registry-photon:v2.11.1 "/home/harbor/entryp…" 6 minutes ago Up 6 minutes (healthy) registry
27a4de039809 goharbor/harbor-registryctl:v2.11.1 "/home/harbor/start.…" 6 minutes ago Up 6 minutes (healthy) registryctl
426620cf7a97 goharbor/harbor-portal:v2.11.1 "nginx -g 'daemon of…" 6 minutes ago Up 6 minutes (healthy) harbor-portal
605cae889833 goharbor/harbor-log:v2.11.1 "/bin/sh -c /usr/loc…" 6 minutes ago Up 6 minutes (healthy) 127.0.0.1:1514->10514/tcp harbor-log
harbor 的运行依赖于9个容器!

相关文章
|
1月前
|
Docker 容器
Docker自建仓库之Harbor高可用部署实战篇
关于如何部署Harbor高可用性的实战教程,涵盖了从单机部署到镜像仓库同步的详细步骤。
77 15
Docker自建仓库之Harbor高可用部署实战篇
|
27天前
|
存储 Kubernetes Cloud Native
部署Kubernetes客户端和Docker私有仓库的步骤
这个指南涵盖了部署Kubernetes客户端和配置Docker私有仓库的基本步骤,是基于最新的实践和工具。根据具体的需求和环境,还可能需要额外的配置和调整。
51 1
|
6天前
|
存储 应用服务中间件 开发工具
docker镜像上传至Harbor及从Harbor下载
docker镜像上传至Harbor及从Harbor下载
|
8天前
|
数据可视化 应用服务中间件 nginx
Docker如何连接至本地私服Harbor中 推送镜像、查看镜像、下载镜像
Docker如何连接至本地私服Harbor中 推送镜像、查看镜像、下载镜像
26 0
|
1月前
|
存储 测试技术 数据安全/隐私保护
Docker自建仓库之Harbor部署实战
关于如何部署和使用Harbor作为Docker企业级私有镜像仓库的详细教程。
198 12
|
1月前
|
Docker 容器
Docker Hub镜像公共仓库使用
这篇文章介绍了如何使用Docker Hub公共仓库进行镜像的创建、上传、下载和管理。
586 8
|
1月前
|
运维 数据安全/隐私保护 Docker
Docker自建仓库之Docker Registry部署实战
关于如何使用Docker Registry镜像搭建本地私有Docker仓库的实战教程,包括了下载镜像、创建授权目录和用户名密码、启动Registry容器、验证端口和容器、测试登录仓库、上传和下载镜像的详细步骤。
276 5
|
1月前
|
应用服务中间件 nginx 数据安全/隐私保护
使用Harbor搭建Docker私有仓库
Harbor是一款开源的企业级Docker仓库管理工具,分为私有与公有仓库两种类型,其中私有仓库被广泛应用于运维场景。Harbor提供图形化界面,便于直观操作,并且其核心组件均由容器构建而成,因此安装时需预先配置Docker及docker-compose。Harbor支持基于项目的用户与仓库管理,实现细粒度的权限控制;具备镜像复制、日志收集等功能,并可通过UI直接管理镜像,支持审计追踪。部署Harbor涉及配置文件调整、登录认证等步骤,并可通过客户端进行镜像的上传、拉取等操作。系统内置多种角色,包括受限访客、访客、开发者、维护人员及管理员,以满足不同场景下的使用需求。
95 0
|
3天前
|
网络协议 网络安全 Docker
docker容器间无法通信
【10月更文挑战第4天】
13 3
|
2天前
|
Docker 容器
docker中检查容器的网络模式
【10月更文挑战第5天】
5 1