harbor

harbor简介

无论是使用Docker-distribution去自建仓库,还是通过官方镜像跑容器的方式去自建仓库,通过前面的演示我们可以发现其是非常的简陋的,还不如直接使用官方的Docker Hub去管理镜像来得方便,至少官方的Docker Hub能够通过web界面来管理镜像,还能在web界面执行搜索,还能基于Dockerfile利用Webhooks和Automated Builds实现自动构建镜像的功能,用户不需要在本地执行docker build,而是把所有build上下文的文件作为一个仓库推送到github上,让Docker Hub可以从github上去pull这些文件来完成自动构建。

但无论官方的Docker Hub有多强大,它毕竟是在国外,所以速度是最大的瓶颈,我们很多时候是不可能去考虑使用官方的仓库的,但是上面说的两种自建仓库方式又十分简陋,不便管理,所以后来就出现了一个被 CNCF 组织青睐的项目,其名为Harbor。

Harbor是由VMWare在Docker Registry的基础之上进行了二次封装,加进去了很多额外程序,而且提供了一个非常漂亮的web界面。

Project Harbor是一个开源的受信任云本地注册表项目,用于存储、标记和扫描上下文。
Harbor通过添加用户通常需要的功能,如安全性、身份标识和管理,扩展了开源Docker发行版。
Harbor支持用户管理、访问控制、活动监控和实例之间的复制等高级特性。

harbor的功能
Feathers:

 - 多租户内容签名和验证
 - 安全性和漏洞分析
 - 审计日志记录
 - 身份集成和基于角色的访问控制
 - 实例之间的映像复制
 - 可扩展的API和图形UI
 - 国际化(现时为中、英文)

Docker compose
Harbor在物理机上部署是非常难的,而为了简化Harbor的应用,Harbor官方直接把Harbor做成了在容器中运行的应用,而且这个容器在Harbor中依赖类似redis、mysql、pgsql等很多存储系统,所以它需要编排很多容器协同起来工作,因此VMWare Harbor在部署和使用时,需要借助于Docker的单机编排工具(Docker compose)来实现。

Compose是一个用于定义和运行多容器Docker应用程序的工具。使用Compose,您可以使用一个YAML文件来配置应用程序的服务。然后,使用一个命令,您可以从您的配置中创建并启动所有的服务。

harbor部署

主机下载docker
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost ~]# curl -o docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
sed -i 's@https://download.docker.com@https://mirrors.tuna.tsinghua.edu.cn/docker-ce@g' docker-ce.repo

[root@localhost ~]# yum -y install docker-ce
[root@localhost ~]# systemctl start docker
配置加速器
[[root@node02  docker]# vim daemon.json 
[[root@node02  docker]# cat daemon.json 
{	
    "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/","https://registry.docker-cn.com"]
}

安装docker compose工具默认8.0没有安装所以需要通过python工具安装
[root@node02 ~]# yum list all|grep python   过滤关于Python的包
[root@node02 ~]# yum -y install python38 安装python38版本,然后通过pip3命令安装
[root@node02 ~]# pip3 install docker-compose   安装docker compose工具

把提前下载的harbor的包解压到/usr/local
[root@node02 ~]# ls   
anaconda-ks.cfg    harbor-offline-installer-v2.3.2.tgz  
[root@node02 src]# tar xf harbor-offline-installer-v2.3.2.tgz -C /usr/local/
[root@node02 src]# ls /usr/local/
bin  etc  games  harbor  include  lib  lib64  libexec  sbin  share  src
[root@node02 src]# cd /usr/local/harbor/
[root@node02 harbor]# ls
common     install.sh  prepare
common.sh  harbor.v2.3.2.tar.gz  harbor.yml.tmpl  LICENSE
编辑文件修改hostname为虚拟机地址
[root@node02 harbor]# vim harbor.yml.tmpl
...
hostname: 192.168.88.128

再把https相关添加注释
#https:  
  # https port for harbor, default is 443
#  port: 443
  # The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path

...

[root@node02 harbor]# ./install.sh   会报错因为没有找到文件
[root@node02 harbor]# cp harbor.yml.tmpl harbor.yml
[root@node02 harbor]# ls
common     harbor.yml       install.sh  prepare
common.sh  harbor.v2.3.2.tar.gz  harbor.yml.tmpl  LICENSE

[root@node02 harbor]# ./install.sh   执行发现成功

[root@node02 harbor]# ls   //可以发现新生成了一个docker-comprose文件
common     docker-compose.yml    harbor.yml       install.sh  prepare
common.sh  harbor.v2.3.2.tar.gz  harbor.yml.tmpl  LICENSE

[root@node02 harbor]# ss -antl
State       Recv-Q Send-Q                   Local Address:Port                                  Peer Address:Port              
LISTEN      0      128                          127.0.0.1:1514                                             *:*                  
LISTEN      0      128                                  *:22                                               *:*                  
LISTEN      0      128                               [::]:80                                            [::]:*                  
LISTEN      0      128                               [::]:22                                            [::]:* 

通过IP地址访问

在这里插入图片描述

登录默认用户名是admin,密码在harbor.yml文件中查看

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

使用IP登录管理Harbor:
使用Harbor的注意事项:

1.在客户端上传镜像时一定要记得执行docker login进行用户认证,否则无法直接push
2.在客户端使用的时候如果不是用的https则必须要在客户端的/etc/docker/daemon.json配置文件中配置insecure-registries参数

[[root@node02  docker]# vim daemon.json 
[[root@node02  docker]# cat daemon.json 
{	
    "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/","https://registry.docker-cn.com"],
    "insecure-registries":["http://192.168.88.128"]      //添加的内容是虚拟机的地址,协议为http
}
[root@node02  docker]# systemctl daemon-reload          重启服务
[root@node02  docker]# systemctl restart docker

可以发现harbor仓库已经停掉
root@node02 harbor]# ss -antl      //可以看到1514端口号已经没有了
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process     
LISTEN     0          128                  0.0.0.0:5000              0.0.0.0:*                                  
LISTEN     0          128                  0.0.0.0:80                0.0.0.0:*                   
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                   
LISTEN     0          128                     [::]:5000                 [::]:*                   
LISTEN     0          128                     [::]:80                   [::]:*                   
LISTEN     0          128                     [::]:22                   [::]:*         
开启harbor仓库,必须进入有docker-compose.yml文件的目录
[root@node02  ~]# cd /usr/local/harbor/
[root@node02 harbor]# ls
common     docker-compose.yml    harbor.yml       install.sh  prepare
common.sh  harbor.v2.3.2.tar.gz  harbor.yml.tmpl  LICENSE
[root@node02 harbor]# docker-compose start
[root@node02 harbor]# ss -antl      //可以看到1514端口号已经启动
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process     
LISTEN     0          128                  0.0.0.0:5000              0.0.0.0:*                   
LISTEN     0          128                127.0.0.1:1514              0.0.0.0:*                   
LISTEN     0          128                  0.0.0.0:80                0.0.0.0:*                   
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                   
LISTEN     0          128                     [::]:5000                 [::]:*                   
LISTEN     0          128                     [::]:80                   [::]:*                   
LISTEN     0          128                     [::]:22                   [::]:*                   

3.数据存放路径应在配置文件中配置到一个容量比较充足的共享存储中
4.Harbor是使用docker-compose命令来管理的,如果需要停止Harbor也应用docker-compose stop来停止,其他参数请–help

上传镜像到harbor

点击项目点击添加
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
修改镜像标签
在这里插入图片描述
上传镜像

[root@node02  ~]# docker logout   退出官方仓库
Removing login credentials for https://index.docker.io/v1/
登录harbor仓库,用户名和密码都是登录网页版的时候输入的
[root@node02  ~]# docker login 192.168.88.128
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
上传
[root@node02  ~]# docker push 192.168.88.128/web/httpd:v0.2
The push refers to repository [192.168.88.128/web/httpd]
62c6656c6e3e: Pushed 
5b8c72934dfc: Pushed 
v0.2: digest: sha256:d658529d11b7ec9c4af470d92c6c8e62a30eaadb630f3e544a10d20544414a07 size: 734

网站验证效果
在这里插入图片描述
拉镜像,先把本地镜像删除

[root@node02  ~]# docker rmi 192.168.88.128/web/httpd:v0.2
Untagged: 192.168.88.128/web/httpd:v0.2
Untagged: 192.168.88.128/web/httpd@sha256:d658529d11b7ec9c4af470d92c6c8e62a30eaadb630f3e544a10d20544414a07

拉取
[root@node02  ~]# docker pull 192.168.88.128/web/httpd:v0.2
v0.2: Pulling from web/httpd
Digest: sha256:d658529d11b7ec9c4af470d92c6c8e62a30eaadb630f3e544a10d20544414a07
Status: Downloaded newer image for 192.168.88.128/web/httpd:v0.2
192.168.88.128/web/httpd:v0.2

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值