CentOS7搭建Harbor企业级Docker仓库

news/2024/7/24 5:09:57 标签: docker, 容器, 运维

docker_0">centos7搭建Harbor企业级docker仓库

前言

Harbor是一个企业级的Docker Registry管理项目,主要用于存储和分发Docker镜像。它提供了一些企业必需的功能特性,如安全、标识和管理等,以扩展开源Docker Distribution。

作为企业级私有Registry服务器,Harbor提供了更好的性能和安全,并提升了用户使用Registry构建和运行环境传输镜像的效率。

Harbor的主要功能包括基于角色的访问控制、用户管理、日志审核、镜像复制和中文支持等。此外,它还提供了诸如项目、日志、仓库管理、同步管理和配置管理等基本功能。

通过这些功能,Harbor可以帮助用户迅速搭建一个企业级的Docker registry服务,确保数据和知识产权在公司内部网络中得到有效管控。

实验环境Centos7.9.2009

docker_2407_14">安装docker 24.0.7版本

curl -sSL https://get.daocloud.io/docker | sh
启动docker 
systemctl start docker

dockercompose_22">安装docker-compose

安装docker-compose的方式有很多种,不推荐一
方式一:
yum update -y
yum -y install epel-release
yum install python-pip
pip install --upgrade setuptools  # 可能由于setuptools版本过低报错
pip install docker-compose  # 如果报错可以试试 --ignore-installed
方式二:
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
方式三:
打开浏览器,访问GitHub上的Compose仓库,找到最新版本的链接。
将下载命令中的Compose替换为最新版本,例如
sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
方式四:
从github上下载docker-compose的二进制文件
https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64
mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
docker-compose version
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

安装Harbor1.7.5

wget -P /usr/local/src/     https://storage.googleapis.com/harbor-releases/release-1.7.0/harbor-online-installer-v1.7.5.tgz  # 在线安装
# 最新版本请查看https://github.com/goharbor/harbor/releases/
cd /usr/local/src/
tar zxf harbor-online-installer-v1.7.5.tgz  -C /usr/local/
cd /usr/local/harbor/
bash install.sh # 使用--with-clair添加镜像漏洞扫描功能
小问题:
➜ Please set hostname and other necessary attributes in harbor.cfg first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.
Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.cfg bacause notary must run under https. 
Please set --with-clair if needs enable Clair in Harbor
Please set --with-chartmuseum if needs enable Chartmuseum in Harbor
 请先在harbor.cfg中设置主机名和其他必要的属性。不要使用localhost或127.0.0.1作为主机名,因为Harbor需要由外部客户端访问。

如果需要,请设置--with公证员在Harbor中启用公证员,并在Harbor.cfg中设置ui_url_procol/ssl_cert/ssl_cert_key,因为公证员必须在https下运行。

请设置——如果需要,请使用clair启用clair in Harbor

请设置——如果需要,请使用图表博物馆在海港启用图表博物馆
需要修改配置文件

Error response from daemon: login attempt to http://myharbor.com/v2/ failed with status: 404 Not Found
修改vim  /etc/hosts
Error response from daemon: Get "http://myharbor.com/v2/": dial tcp 192.168.40.106:80: connect: connection refused


修改配置文件

vim /usr/local/harbor/harbor.cfg  # harbor配置文件

# 找到以下项目并且修改
hostname = myharbor.com  # 修改访问域名,如果使用其它端口,请在后面添加端口号,如test.com:8080
#邮箱配置(根据实际账号配置)
email_server = smtp.qq.com
email_server_port = 465
email_username = myharbor@qq.com
email_password = 123456
email_from = myharbor@qq.com  # 经测试发现必须要和email_username相同才可以发邮件
email_ssl = true  # 开启ssl保护,使用端口465,关闭使用端口25
#禁止用户注册
self_registration = off
#设置只有管理员可以创建项目
project_creation_restriction = adminonly
#设置管理员密码
harbor_admin_password = 123456

对Harbor容器集群管理

cd /usr/local/harbor/
docker-compose ps  # 查看harbor集群容器,安装后已经启动
# ---------- 控制 ----------
# 必须要在/usr/local/harbor/目录下,或者-f指定docker-compose.yml
# 启动Harbor
docker-compose start
# 停止Harbor
docker-comose stop
# 重启Harbor
docker-compose restart
# 移除Harbor
docker-compose down -v  # -v 参数移除vloume
# 重新创建并启动
docker-compose up -d
# ---------- 控制 ----------
登录harbor

默认账号是 admin 密码是 Harbor12345

如有需要可以 修改nginx端口
vim /usr/local/harbor/docker-compose.yml
# 把proxy下的80:80改为8080:80则为使用8080访问harbor
docker-compose stop proxy  # proxy其实就是nginx
docker-compose up -d proxy  # 重新开启nginx
netstat -lntp # 查看本地打开端口,如果有docker-proxy为8080则修改成功
# 如果有安全组防火墙,记得先放行对应端口

Harbor上传、下载镜像

# 由于使用80端口需要备案,harbor页面已经修改为8080端口(注意修改harbor.cfg的hostname后需要重新执行install.sh)
vim /etc/docker/daemon.json
# 添加 {"insecure-registries":["myharbor.com"]} 
systemctl daemon-reload  
systemctl restart docker

# 注意此处需要添加端口
docker login myharbor.com:80
假如修改了端口则是:
docker login test.com:8080  # 尝试登录

# 编写dockerfile
mkdir harbortest && cdharbortest 
cat << EOF > Dockerfile
FROM nginx:latest
MAINTAINER test "test@qq.com"
# 配置环境变量
ENV LANG=C.UTF-8 TZ=Asia/Shanghai
EO
# build镜像
docker build -t myharbor.com:80/library/nginx:latest .
# push镜像到远程仓库
docker push myharbor.com:80/library/nginx:latest
# 从远程仓库拉取镜像
docker pull myharbor.com:80/library/nginx:latest

http://www.niftyadmin.cn/n/5319763.html

相关文章

【工具栏】Rainbow Brackets(彩虹括号) 插件的安装和使用

使用前 这一段代码里有这么多括号&#xff0c;找到相匹配的括号需要花点时间 &#xff0c;但是安装Rainbow Brackets插件后&#xff0c;代码在括号方面多一份美观 安装 效果如下&#xff1a;

js封装根据年月日获取星座效果demo(整理)

//根据年月日获取星座 function getZodiacSign(dateString) {// 用法:const dateStr 2024-01-11;// const zodiacSign getZodiacSign(dateStr);const date new Date(dateString);const month date.getMonth() 1;const day date.getDate();if ((month 1 && day &…

Android基于Matrix绘制PaintDrawable设置BitmapShader,以手指触点为中心显示原图像圆图,Kotlin(2)

Android基于Matrix绘制PaintDrawable设置BitmapShader&#xff0c;以手指触点为中心显示原图像圆图&#xff0c;Kotlin&#xff08;2&#xff09; 在 https://zhangphil.blog.csdn.net/article/details/135374279 基础上&#xff0c;增加一个功能&#xff0c;当手指在上面的图片…

c++对象拷贝与堆中的对象实例拷贝

文章目录 拷贝构造函数等于号运算符总结深拷贝堆中对象实例的拷贝错误的方法正确的拷贝方法使用多态技术拷贝实例拷贝构造函数 拷贝构造函数是C++中的一种特殊的构造函数,用于创建一个新对象,该对象是已存在的对象的副本。 拷贝构造函数的语法如下: class ClassName {// .…

ES索引原理

ES在检索时底层使用的就是倒排索引&#xff0c;正向索引是通过key找value&#xff0c;反向索引则是通过value找key。 索引会分为两个区域&#xff1a;索引区和元数据区。数据是这样存储在里面的&#xff1a; 简单理解就是&#xff1a;当要录入一条数据时&#xff0c;首先会将完…

基于springboot+vue药店管理系统

摘要 药店管理系统的设计和应用在当前社会背景下具有巨大的实际意义和社会价值。随着医药行业的不断发展和社会健康水平的提高&#xff0c;药店作为医疗服务的一部分&#xff0c;其管理方式也需要不断创新与优化。该系统的研究不仅关系到单一药店的运营效率&#xff0c;更涉及到…

Elasticsearch地理位置数据索引

地理位置数据索引 在 Elasticsearch 中&#xff0c;地理位置数据的索引涉及两种主要的字段类型&#xff1a;geo_point 和 geo_shape。这些字段类型允许 Elasticsearch 存储和查询地理空间数据&#xff0c;如坐标点、线和多边形。 geo_point Elasticsearch的geo_point字段类型…

【验证码识别专栏】人均通杀点选验证码!Yolov5 + 孪生神经网络 or 图像分类 = 高精模型

声明 本文章中所有内容仅供学习交流使用&#xff0c;不用于其他任何目的&#xff0c;严禁用于商业用途和非法用途&#xff0c;否则由此产生的一切后果均与作者无关&#xff01; 本文章未经许可禁止转载&#xff0c;禁止任何修改后二次传播&#xff0c;擅自使用本文讲解的技术…