Harbor部署docker私人仓库

1、新建虚拟机rhel9

2、配置网络

#修改内核参数使网卡名称为ethxxx
grubby --update-kernel ALL --args net.ifnames=0

reboot
#配置网络
vim /etc/NetworkManager/system-connections/eth0.connection
内容为:

[connection]
id=eth0
type=ethernet
interface-name=eth0

[ipv4]
method=manual
address1=172.25.254.250/24,172.25.254.2
dns=114.114.114.114

[root@localhost system-connections]# chmod 600 eth0.nmconnection 
[root@localhost system-connections]# nmcli connection reload 
[root@localhost system-connections]# nmcli connection up eth0 

3、挂载本地软件仓库

#临时挂载
[root@localhost ~]# mkdir /rhel9
[root@localhost images]# mount /dev/sr0 /rhel9/

#永久挂载:编辑文件
[root@localhost images]# vim /etc/rc.d/rc.local 
内容:
mount /dev/sr0 /rhel9

#编辑本地源
vim /etc/yum.repos.d/rhel9.repo

内容:
[AppStream]
name=AppStream
baseurl=file:///rhel9/AppStream
gpgcheck=0

[BaseOS]
name=BaseOS
baseurl=file:///rhel9/BaseOS
gpgcheck=0

4、下载docker

[root@localhost images]# tar zxf docker.tar.gz
[root@localhost images]# dnf install *.rpm -y
[root@localhost images]# systemctl enable --now docker.service

5、挂载镜像

[root@localhost ~]# mkdir images

#将所需镜像全部放入images目录中
#全部挂载
[root@localhost images]# for i in `ls /root/images`; do docker load -i $i; done

6、生成证书

[root@localhost ~]# mkdir /data/certs -p
#创建证书
[root@localhost certs]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout /data/certs/gaoyingjie.org.key -addext "subjectAltName = DNS:reg.gaoyingjie.org" -x509 -days 365 -out /data/certs/gaoyingjie.org.crt

#让docker读取证书
[root@localhost ~]# mkdir /etc/docker/certs.d/reg.gaoyingjie.org/ -p
[root@localhost ~]# cp /data/certs/gaoyingjie.org.crt /etc/docker/certs.d/reg.gaoyingjie.org/ca.crt
[root@localhost ~]# systemctl restart docker.service

7、部署harbor

[root@localhost ~]# tar zxf harbor-offline-installer-v2.5.4.tgz 
[root@localhost ~]# cd harbor/
[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml
[root@localhost harbor]# vim harbor.yml

内容:
hostname: reg.gaoyingjie.org
certificate: /data/certs/gaoyingjie.org.crt
private_key: /data/certs/gaoyingjie.org.key
harbor_admin_password: gyj

[root@localhost harbor]# ./install.sh  --with-chartmuseum
[root@localhost harbor]# docker compose stop
[root@localhost harbor]#  docker compose up -d

#编辑本地解析
[root@localhost harbor]# vim /etc/hosts
172.25.254.250  docker-harbor reg.gaoyingjie.org

8、建立登录认证

[root@localhost ~]# mkdir auth
[root@localhost ~]#  htpasswd -Bc auth/htpasswd gaoyingjie
New password: 
Re-type new password: 
Adding password for user gyj

9、编辑本地dns解析

#修改主机名:
hostnamectl hostname docker-harbor

#修改dns解析
[root@docker-harbor ~]# vim /etc/hosts

内容:
172.25.254.250 docker-harbor reg.gaoyingjie.org

10、登录harbor

[root@docker-harbor ~]#  docker login reg.gaoyingjie.org
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

11、一键添加tag

[root@docker-harbor ~]# docker images | awk 'NR>1{system("docker tag "$1":"$2" reg.gaoyingjie.org/library/"$1":"$2)}'

12、一键push上传到harbor仓库

[root@docker-harbor ~]# docker images | awk '/reg.gaoyingjie.org/{system("docker push "$1":"$2)}'
相关推荐
sj11637394034 分钟前
docker-compose方式启动Kafka Sasl加密认证(无zk)
docker·kafka
likfishdn21 分钟前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean40 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=42 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
Dontla1 小时前
Docker run --add-host参数解析(在容器启动时向/etc/hosts文件中添加自定义的主机名与IP映射)(适用于临时调试或测试)
tcp/ip·docker·容器
西西小飞龙1 小时前
Docker和K8S中pod、services、container的介绍和关系
docker·容器·kubernetes
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
kngines1 小时前
【实战 ES】实战 Elasticsearch:快速上手与深度实践-1.3.1单节点安装(Docker与手动部署)
大数据·elasticsearch·docker
北京耐用通信2 小时前
航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
运维·机器人·自动化
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net