Docker搭建私有仓库harbor(docker 镜像仓库搭建)

news2024/9/24 3:25:44
  • Harbor介绍

Docker容器应用的开发和运行离不开可靠的镜像管理,虽然Docker官方也提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署我们私有环境内的Registry也是非常必要的。Harbor是由VMware公司开源的企业级的Docker
Registry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能。
官网地址:https://github.com/goharbor/harbor

Docker Harbor是一个企业级的Docker Registry服务,旨在提供安全、可靠的镜像存储和管理解决方案。以下是Docker
Harbor的一些关键特点:

  1. 私有Registry:Docker Harbor允许用户搭建私有的Docker Registry,使得企业可以在自己的内部网络中安全地存储和管理Docker镜像。
  2. 安全性:Docker Harbor提供了访问控制、用户和团队管理功能,以确保镜像的安全性。它支持用户身份验证、权限控制、安全扫描等功能,帮助用户保护他们的容器镜像不受未经授权的访问。
  3. 可扩展性:Docker Harbor支持集群部署,可以轻松地扩展以应对大规模的容器镜像存储需求。
  4. 镜像复制和同步:Docker Harbor允许用户在不同的Registry之间复制和同步镜像,方便用户在多个部署环境之间共享和管理镜像。
  5. 审计和日志记录:Docker Harbor提供审计和日志记录功能,记录用户对镜像的操作,以帮助用户跟踪镜像的变更历史。 总的来说,Docker Harbor是一个功能强大的企业级Docker
    Registry服务,为用户提供了安全、可靠的方式来管理和存储Docker镜像。
  • 所需要的安装包

链接:https://pan.baidu.com/s/1rN25l72i6W36ANAOqxcc_w 提取码:1021

  1. 为harbor签发证书
[root@harbor ~]# hostnamectl set-hostname harbor && /bin/bash
[root@harbor ~]# mkdir /data/ssl -p
[root@harbor ~]# cd /data/ssl/

#生成ca证书
#生成一个3072位的key,也就是私钥
[root@harbor ssl]# openssl genrsa -out ca.key 3072
Generating RSA private key, 3072 bit long modulus
...........++
.............++
e is 65537 (0x10001)
#生成一个数字证书ca.pem,3650表示证书的有效时间是3年,按箭头提示填写即可,没有箭头标注的为空:
[root@harbor ssl]# openssl req -new -x509 -days 3650 -key ca.key -out ca.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CH
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:BJ
Organizational Unit Name (eg, section) []:BJ
Common Name (eg, your name or your server's hostname) []:CHONG
Email Address []:123@163.com

#生成域名的证书
#生成一个3072位的key,也就是私钥
[root@harbor ssl]# openssl genrsa -out harbor.key  3072
Generating RSA private key, 3072 bit long modulus
.++
..........................................................++
e is 65537 (0x10001)
#生成一个证书请求,一会签发证书时需要的,标箭头的按提示填写,没有箭头标注的为空:
[root@harbor ssl]# openssl req -new -key harbor.key -out harbor.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CH
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:harbor  #主机名
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
#签发证书
[root@harbor ssl]# openssl x509 -req -in harbor.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out harbor.pem -days 3650
#显示如下说明证书发布完成
Signature ok
subject=/C=CH/ST=BJ/L=BJ/O=Default Company Ltd/CN=harbor
Getting CA Private Key

注:安装harbor需要docker,记得安装docker

  1. 安装harbor
#创建harbor安装目录
[root@harbor ~]# mkdir /data/install -p
[root@harbor ~]# cd /data/install/
#上传harbor离线包到该目录:harbor-offline-installer-v2.3.0-rc3.tgz
#下载harbor离线包的地址:https://github.com/goharbor/harbor/releases/tag/
[root@harbor install]# ll
total 614492
-rw-r--r-- 1 root root 629238614 Apr 11 21:40 harbor-offline-installer-v2.3.0-rc3.tgz

#解压该安装包
[root@harbor install]# tar -xf harbor-offline-installer-v2.3.0-rc3.tgz
[root@harbor install]# ll
total 614492
drwxr-xr-x 2 root root       122 Apr 11 21:42 harbor
-rw-r--r-- 1 root root 629238614 Apr 11 21:40 harbor-offline-installer-v2.3.0-rc3.tgz
[root@harbor install]# cd harbor
[root@harbor harbor]# ll
total 617800
-rw-r--r-- 1 root root      3361 Jun 17  2021 common.sh
-rw-r--r-- 1 root root 632593607 Jun 17  2021 harbor.v2.3.0.tar.gz
-rw-r--r-- 1 root root      7840 Jun 17  2021 harbor.yml.tmpl
-rwxr-xr-x 1 root root      2500 Jun 17  2021 install.sh
-rw-r--r-- 1 root root     11347 Jun 17  2021 LICENSE
-rwxr-xr-x 1 root root      1881 Jun 17  2021 prepare
[root@harbor harbor]# cp harbor.yml.tmpl harbor.yml

#修改配置
[root@harbor harbor]# vim harbor.yml

只修改三种地方 一个是主机名 一个是key和pem得位置
在这里插入图片描述

  1. 安装docker-compose

上传docker-compose-Linux-x86_64文件到harbor机器

[root@harbor harbor]# ll
total 629776
-rw-r--r-- 1 root root      3361 Jun 17  2021 common.sh
-rw-r--r-- 1 root root  12254160 Apr 11 22:44 docker-compose-Linux-x86_64.64
-rw-r--r-- 1 root root 632593607 Jun 17  2021 harbor.v2.3.0.tar.gz
-rw-r--r-- 1 root root      7826 Apr 11 22:41 harbor.yml
-rw-r--r-- 1 root root      7840 Jun 17  2021 harbor.yml.tmpl
-rwxr-xr-x 1 root root      2500 Jun 17  2021 install.sh
-rw-r--r-- 1 root root     11347 Jun 17  2021 LICENSE
-rwxr-xr-x 1 root root      1881 Jun 17  2021 prepare
You have new mail in /var/spool/mail/root
[root@harbor harbor]# mv docker-compose-Linux-x86_64.64 /usr/bin/docker-compose
[root@harbor harbor]# chmod +x /usr/bin/docker-compose
[root@harbor harbor]# /bin/bash
[root@harbor harbor]# docker-compose version
docker-compose version 1.26.2, build eefe0d31
docker-py version: 4.2.2
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019
[root@harbor harbor]#
  1. 上传harbor所需要得镜像

docker-harbor-2-3-0.tar.gz

#解压镜像
[root@harbor harbor]# docker load -i docker-harbor-2-3-0.tar.gz
[root@harbor harbor]# docker images
REPOSITORY                      TAG       IMAGE ID       CREATED       SIZE
goharbor/harbor-exporter        v2.3.0    fa4ecf260b3a   2 years ago   80.7MB
goharbor/chartmuseum-photon     v2.3.0    199be7eb1b5b   2 years ago   178MB
goharbor/redis-photon           v2.3.0    3cc2c3e315a2   2 years ago   191MB
goharbor/trivy-adapter-photon   v2.3.0    3c3dc5fc0529   2 years ago   164MB
goharbor/notary-server-photon   v2.3.0    a8e3a26ef25a   2 years ago   105MB
goharbor/notary-signer-photon   v2.3.0    e8776cc92436   2 years ago   102MB
goharbor/harbor-registryctl     v2.3.0    4cf0d9bc3086   2 years ago   132MB
goharbor/registry-photon        v2.3.0    222f05a9ab07   2 years ago   81MB
goharbor/nginx-photon           v2.3.0    78f6ae7adc04   2 years ago   44MB
goharbor/harbor-log             v2.3.0    9446a5b39706   2 years ago   194MB
goharbor/harbor-jobservice      v2.3.0    bac328ac1a47   2 years ago   170MB
goharbor/harbor-core            v2.3.0    7bbebce7798c   2 years ago   157MB
goharbor/harbor-portal          v2.3.0    c4f22964cbf3   2 years ago   57.3MB
goharbor/harbor-db              v2.3.0    fc74663d9e30   2 years ago   262MB
goharbor/prepare                v2.3.0    a830321ca695   2 years ago   291MB

#安装harbor
[root@harbor harbor]# cd /data/install/harbor
[root@harbor harbor]# ./install.sh

看到以下内容 成名成功
在这里插入图片描述
5. 安装成功

默认用户名:admin
默认密码:Harbor12345

在这里插入图片描述
在这里插入图片描述
6. 新建项目

在这里插入图片描述
在这里插入图片描述

  1. 其他docker机器配置该镜像仓库
#两台服务器配置本地hosts
vim /etc/hosts
192.168.40.180 test-server01
192.168.40.181 harbor

#修改180机器得daemon.json配置
[root@test-server01 ~]# vim /etc/docker/daemon.json

{
  "registry-mirrors":["https://vl2nkrv0.mirror.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","https://dockerhub.azk8s.cn","http://hub-mirror.c.163.com"],
  "insecure-registries": ["192.168.40.181","harbor"]
}
#harbor机器得IP和主机名

#重启docker
[root@test-server01 ~]# systemctl restart docker
  1. docker登录harbor进行测试
[root@test-server01 ~]# docker login 192.168.40.181
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/#credentials-store
Login Succeeded

#打包一个镜像上传到test项目
[root@test-server01 ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
tomcat        v1        422fe599256a   4 weeks ago   803MB
nginx         v1        f436f09d9c6c   4 weeks ago   342MB
inter-image   latest    5eb7b6cd9fb7   4 weeks ago   342MB
volume        latest    4fd3ed843dab   2 years ago   231MB
centos        latest    5d0da3dc9764   2 years ago   231MB
[root@test-server01 ~]#
#以本机有的镜像tomcat为例进行打标签

[root@test-server01 ~]# docker tag tomcat:v1  192.168.40.181/test/tomcat:v1
[root@test-server01 ~]# docker images
REPOSITORY                   TAG       IMAGE ID       CREATED       SIZE
192.168.40.181/test/tomcat   v1        422fe599256a   4 weeks ago   803MB
tomcat                       v1        422fe599256a   4 weeks ago   803MB
nginx                        v1        f436f09d9c6c   4 weeks ago   342MB
inter-image                  latest    5eb7b6cd9fb7   4 weeks ago   342MB
centos                       latest    5d0da3dc9764   2 years ago   231MB
volume                       latest    4fd3ed843dab   2 years ago   231MB
#上传打上标签得镜像
[root@test-server01 ~]#  docker push 192.168.40.181/test/tomcat:v1
The push refers to repository [192.168.40.181/test/tomcat]
baa34f4b2d36: Pushed
9098e168cf25: Pushed
8e1cd85f5863: Pushed
70e115906be4: Pushed
6900d18cbe12: Pushed
49461804abc1: Pushed
2e412669ee56: Pushed
74ddd0ec08fa: Pushed
v1: digest: sha256:99c83711e386c7de760bc2c549b231995928bcb37b0d27b7d6478b6c332a5200 size: 1999
#成功上传到镜像仓库
  1. harbor web页面查看

已经有这个tomcat包在这里插入图片描述

  1. 测试从harbor下载镜像
#删除本地镜像

[root@test-server01 ~]# docker images |grep test/tomcat
192.168.40.181/test/tomcat   v1        422fe599256a   4 weeks ago   803MB
[root@test-server01 ~]# docker rmi 192.168.40.181/test/tomcat:v1
Untagged: 192.168.40.181/test/tomcat:v1
Untagged: 192.168.40.181/test/tomcat@sha256:99c83711e386c7de760bc2c549b231995928bcb37b0d27b7d6478b6c332a5200
[root@test-server01 ~]# docker images |grep test/tomcat

#下载镜像
[root@test-server01 ~]# docker pull 192.168.40.181/test/tomcat:v1
v1: Pulling from test/tomcat
Digest: sha256:99c83711e386c7de760bc2c549b231995928bcb37b0d27b7d6478b6c332a5200
Status: Downloaded newer image for 192.168.40.181/test/tomcat:v1
192.168.40.181/test/tomcat:v1
You have new mail in /var/spool/mail/root
[root@test-server01 ~]# docker images |grep test/tomcat
192.168.40.181/test/tomcat   v1        422fe599256a   4 weeks ago   803MB

页面可以看到下载次数已经是1了在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1950269.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

王春城:如何通过看板实现限制在制品数量的目标?

在制造业中,限制在制品(Work-in-Process, WIP)数量是提高生产效率、减少浪费并优化资源利用的关键一环。通过实施看板系统(Kanban System),企业可以有效地管理生产流程,确保在制品数量在合理范围…

【宝藏系列】模/数转换十大常用滤波算法

【宝藏系列】模/数转换十大常用滤波算法 文章目录 【宝藏系列】模/数转换十大常用滤波算法👨‍🏫ADC(Analog-to-Digital Converter,模数转换器)1️⃣限幅滤波法2️⃣中位值滤波法3️⃣算术平均滤波法4️⃣递推平均滤波…

自养号测评:lazada、shopee商家销量提升的必备武器

在东南亚电商跨境平台中、lazada、shopee是东南亚地区最大的在线购物网站,其目标主要是印地,马来,台湾,菲律宾,新加坡,泰国和越南等用户。而自养号补单作为一种有效的推广手段,正逐渐被越来越多…

了解高防 IP

一、高防 IP 的基本概念 高防 IP 是指拥有强大防御能力的 IP 地址。它主要通过将攻击流量引流到高防机房进行清洗和过滤,再将正常的流量回注到源站,从而保障源站服务器的稳定运行。 二、高防 IP 的工作原理 当用户的服务器遭受 DDoS 攻击时&#xff0…

shell脚本及判断语句

一、shell相关概念 1、shell概念 Shell 是一个命令行解释器,它提供了一个用户与操作系统进行交互的界面。通过 Shell,用户可以输入命令来执行程序、管理系统资源(如文件和目录)、以及执行各种系统级的任务。Shell 是大多数类 Un…

从食堂采购系统源码到成品:打造供应链采购管理平台实战详解

本篇文章,笔者将详细介绍如何从食堂采购系统的源码开始,逐步打造一个完备的供应链采购管理平台,帮助企业实现采购流程的智能化和高效化。 一、需求分析与规划 一般来说,食堂采购系统需要具备以下基本功能: 1.供应商…

原生PHP/JS自主开发的交友内核框架婚恋交友系统V10

本文来自:婚恋交友系统V10 - 源码1688 应用介绍 原生PHP/JS自主开发的交友内核框架,极高性能、无捆绑、自主权、无流水扣点、独立全开源 01脱单盲盒:脱单盲盒类似于漂流瓶,先将自己《投放》到盲盒中,另一伴有缘将您取…

文件上传总结

一、原理 通过界面上的上传功能上传了一个可执行的脚本文件,而WEB端的系统并未对其进行检测或者检测的逻辑做的不够好,使得恶意用户可以通过文件中上传的一句话木马获得操控权 二、绕过方法 1>前端绕过 1.删除前端校验函数 checkFile() 2.禁用js…

Python小工具——监听某网站的数据变化并进行邮件通知

目录 一、需求描述 二、解析 三、实例代码 一、需求描述 监听自考网2024年广东省6月份的毕业生学历注册进度,这是网址:https://www.chsi.com.cn/xlcx/count_zk.jsp, 如上图所示,我们想知道这个红色的空格啥时候被填满&#xf…

如何选择财税RPA解决方案

随着大数据、物联网、人工智能以及RPA等新兴技术的迅猛发展,每个企业都面临着巨大的行业和技术挑战。财务作为企业运营管理的核心,其数字化转型成为众多企业提升管理效能和实现高质量发展的先行路径。随着RPA技术应用在财务领域的不断深入,越…

WireShark 更改界面主题

背景 Windows 是黑色主题 安装 WireShark 后&#xff0c;WireShark 界面也是黑色主题 预期 想要将 WireShark 界面更改为白色主题 操作 启动 wireshark 时添加 -platform windows:darkmode0 参数 <Wireshark.exe 路径> -platform windows:darkmode0 例&#xff1a;…

基于PSO粒子群优化的GroupCNN分组卷积网络时间序列预测算法matlab仿真

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 4.1 粒子群优化算法&#xff08;PSO&#xff09; 4.2 分组卷积神经网络&#xff08;GroupCNN&#xff09; 4.3 PSO优化GroupCNN 5.算法完整程序工程 1.算法运行效果图预览 (完整程序运行…

数据结构篇4—递归实现二叉树基础结构

文章目录 前言&#x1f6a9;1、树&#xff1f;2、树的相关概念3、树的结构表示4、二叉树&#x1f680;、概念和结构&#x1f381;、特殊二叉树 5、二叉树常用性质6、二叉树的存储结构&#x1f9e9;、顺序存储结构&#x1f3a8;、链式存储结构 7、二叉树顺序结构的实现----堆8、…

前端开发知识(三)-javascript(对象)

一、JS对象 包括JS已经定义的对象&#xff0c;如&#xff0c;Array,Sting &#xff0c;DOM&#xff0c;BOM等&#xff0c;其中&#xff0c;JSON是用户自定义对象&#xff08;除对象外&#xff0c;还有文本&#xff09;&#xff0c;其他是JS定义 1.Array&#xff1a;数组 数…

React最新版本 18

截至当前时间&#xff08;2024年07月24日&#xff09;&#xff0c;React 的最新版本是 18.2.0。这个版本在 2022 年 3 月 29 日由 React 团队正式发布&#xff0c;主要着眼于解决 React 应用在性能、稳定性、开发体验等方面的问题。 React 18 是 React 的一个重要版本&#xf…

算法导论 总结索引 | 第五部分 第二十章:van Emde Boas树

1、一些支持优先队列操作的 数据结构,如第6章的二叉堆、第13章的红黑树 和 第19章的斐波那契堆。在这几种数据结构中, 不论是最好情况 还是 摊还情况, 至少有一项重要操作 只需要 O(n lgn) 时间 由于这些数据结构 都是基于关键字比较 决定的&#xff0c;因此, 8.1节中的下界 Ω…

【网络流】——初识(最大流)

网络流-最大流 基础信息引入一些概念基本性质 最大流定义 Ford–Fulkerson 增广Edmons−Karp算法Dinic 算法参考文献 基础信息 引入 假定现在有一个无限放水的自来水厂和一个无限收水的小区&#xff0c;他们之间有多条水管和一些节点构成。 每一条水管有三个属性&#xff1a…

sql_exporter通过sql收集业务数据并通过prometheus+grafana展示

下载并解压安装sql_exporter wget https://github.com/free/sql_exporter/releases/download/0.5/sql_exporter-0.5.linux-amd64.tar.gz #解压 tar xvf sql_exporter-0.5.linux-amd64.tar.gz -C /usr/local/修改主配置文件 cd /usr/local/ mv sql_exporter-0.5.linux-amd64 s…

海山数据库(He3DB)技术解析:海山Redis定时任务与持久化管控设计

文章目录 引言一、背景介绍二、具体实现1、多副本容灾功能2、主备切换后任务断点续做功能3、持久化管控编排功能 三、总结作者 引言 云Redis数据库服务是目前广泛应用的模式&#xff0c;其数据持久化方案是现在研究的热点内容&#xff0c;数据持久化操作主要由参数设置自动触发…

AI学习记录 - 激活函数的作用

试验&#xff0c;通过在线性公式加入激活函数&#xff0c;可以拟合复杂的情况&#xff08;使用js实现&#xff09; 结论:1、线性函数的叠加&#xff0c;无论叠加多少次&#xff0c;都是线性的 如下图 示例代码 线性代码&#xff0c;使用ykxb的方式&#xff0c;叠加10个函数…