一、简介
下载地址:https://github.com/goharbor/harbor/releases
Harbor 是由vmware公司开源的企业级 Docker Registry 项目。
它提供了以下主要功能和特点:
- 基于角色的访问控制(RBAC):可以为不同的用户和用户组分配不同的权限,增强了安全性和管理
的灵活性。 - 镜像复制:支持在不同的 Harbor 实例之间复制镜像,方便在多个数据中心或环境中分发镜像。
- 图形化用户界面(UI):提供了直观的 Web 界面,便于管理镜像仓库、项目、用户等。
- 审计日志:记录了对镜像仓库的各种操作,有助于追踪和审查活动。
- 垃圾回收:可以清理不再使用的镜像,节省存储空间。
二、部署安装docker
#下载的docker压缩包
[root@linux9 ~]# yum install *.rpm
[root@linux9 ~]# systemctl start docker
三、部署harbor
#解压
[root@linux9 ~]# tar -zxf harbor-offline-installer-v2.5.4.tgz
[root@linux9 harbor]# cp harbor.yml.tmpl harbor.yml
#创建证书存放的目录
[root@linux9 harbor]# mkdir certs
#生成证书
openssl req -newkey rsa:4096 -nodes -sha256 -keyout /root/harbor/certs/gang.key -addext "subjectAltName = DNS:www.gang.com" -x509 -days 365 -out /root/harbor/certs/gang.crt
[root@linux9 harbor]# vim harbor.yml
hostname: www.gang.com
certificate: /root/harbor/certs/gang.crt
private_key: /root/harbor/certs/gang.key
harbor_admin_password: redhat
#客户端还需要证书验证,方便可以上传自己的docker镜像
[root@linux9 harbor]# mkdir /etc/docker/certs.d/www.gang.com -p
[root@linux9 harbor]# cp certs/gang.crt /etc/docker/certs.d/www.gang.com/ca.crt
#运行安装的命令
[root@linux9 harbor]# ./install.sh --with-chartmuseum
#管理harbor的容器
[root@docker harbor]# docker compose stop
[root@docker harbor]# docker compose up -d
登录harbor
#设置加速地址为自己,那么下载镜像就会从自己的harbor仓库里下载
[root@linux9 ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://172.25.254.120/"]
}
四、上传docker镜像
[root@linux9 ~]# docker login www.gang.com
Username: admin
Password:
Error response from daemon: Get "https://www.gang.com/v2/": tls: failed to verify certificate: x509: certificate is valid for invest.le.cn, not www.gang.com
如果出现这种失败的问题?
1、可能是没有解析www.gang.com这个域名
2、没有配置客户端的证书
3、还没解决的话,重新在安装一次
[root@linux9 ~]# docker tag busybox:latest www.gang.com/library/busybox:latest
[root@linux9 ~]# docker push www.gang.com/library/busybox
Using default tag: latest
The push refers to repository [www.gang.com/library/busybox]
d51af96cf93e: Pushed
latest: digest: sha256:28e01ab32c9dbcbaae96cf0d5b472f22e231d9e603811857b295e61197e40a9b size: 527
验证:
五、拉去镜像
[root@linux9 harbor]# docker pull www.gang.com/library/busybox@sha256:28e01ab32c9dbcbaae96cf0d5b472f22e231d9e603811857b295e61197e40a9b
www.gang.com/library/busybox@sha256:28e01ab32c9dbcbaae96cf0d5b472f22e231d9e603811857b295e61197e40a9b: Pulling from library/busybox
Digest: sha256:28e01ab32c9dbcbaae96cf0d5b472f22e231d9e603811857b295e61197e40a9b
Status: Image is up to date for www.gang.com/library/busybox@sha256:28e01ab32c9dbcbaae96cf0d5b472f22e231d9e603811857b295e61197e40a9b
www.gang.com/library/busybox@sha256:28e01ab32c9dbcbaae96cf0d5b472f22e231d9e603811857b295e61197e40a9b
#还可以这样
[root@linux9 harbor]# docker pull www.gang.com/library/busybox
Using default tag: latest
latest: Pulling from library/busybox
Digest: sha256:28e01ab32c9dbcbaae96cf0d5b472f22e231d9e603811857b295e61197e40a9b
Status: Image is up to date for www.gang.com/library/busybox:latest
www.gang.com/library/busybox:latest