Linux搭建Harbor镜像仓库及使用

小柒博客 Docker2113K8字数 3936阅读13分7秒阅读模式

一、Harbor简介

Harbor 是由 VMware 公司中国团队为企业用户设计的 Registry server 开源项目,包括了权限管理(RBAC)、LDAP、审计、管理界面、自我注册、HA 等企业必需的功能,同时针对中国用户的特点,设计镜像复制和中文支持等功能。

作为一个企业级私有 Registry 服务器,Harbor 提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率。Harbor 支持安装在多个 Registry 节点的镜像资源复制,镜像全部保存在私有 Registry 中, 确保数据和知识产权在公司内部网络中管控。另外,Harbor 也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。

  • 基于角色的访问控制 - 用户与 Docker 镜像仓库通过"项目"进行组织管理,一个用户可以对多个镜像仓库在同一命名空间(project)里有不同的权限。
  • 镜像复制 - 镜像可以在多个 Registry 实例中复制(同步)。尤其适合于负载均衡,高可用,混合云和多云的场景。
  • 图形化用户界面 - 用户可以通过浏览器来浏览,检索当前 Docker 镜像仓库,管理项目和命名空间。
  • AD/LDAP 支持 - Harbor 可以集成企业内部已有的 AD/LDAP,用于鉴权认证管理。
  • 审计管理 - 所有针对镜像仓库的操作都可以被记录追溯,用于审计管理。
  • 国际化 - 已拥有英文、中文、德文、日文和俄文的本地化版本。更多的语言将会添加进来。
  • RESTful API - RESTful API 提供给管理员对于 Harbor 更多的操控, 使得与其它管理软件集成变得更容易。
  • 部署简单 - 提供在线和离线两种安装工具,也可以安装到 vSphere 平台(OVA 方式)虚拟设备。

二、项目介绍

harbor git地址

优点:

  • 本身自带 docker 私有仓库
  • 支持基于角色的权限管理
  • 支持 LDAP

三、harbor安装

运行环境:Centos 7.8

1)需要安装docker并运行

yum -y install docker-ce      # 安装docker

systemctl start docker         # 运行docker服务

2)需要安装docker-compose

yum -y install docker-compose

1、下载安装包

# 版本为1.10.3

[root@Docker ~]# wget https://github.com/goharbor/harbor/releases/download/v1.10.3/harbor-offline-installer-v1.10.3.tgz

2、解压

[root@Docker ~]# tar xf harbor-offline-installer-v1.10.3.tgz

3、安装

[root@Docker ~]# cd harbor

# 修改hostnmae

[root@Docker harbor]# vim harbor.yml

将hostname改成你本机IP即可

# 注释https,不然在安装的时候会报错:ERROR:root:Error: The protocol is https but attribute ssl_cert is not set

其他配置保持默认

[root@Docker harbor]# ./install.sh

可以看到Harbor已经成功安装并启动了。

4、查看Harbor的状态

5、访问私服

打开浏览器访问服务器IP:172.168.1.249,默认用户名密码为:admin/Harbor12345

登录后的第一件事情永远都是修改默认密码。然后就可以在项目管理中新建和管理项目了。不过默认情况下的项目library是公开的,如果你要使用这个项目,而且域名放在公网上,请取消公开。

四、客户端验证

1、安装Docker

[root@localhost ~]# curl -sSL https://get.daocloud.io/docker | sh

# 启动Docker

[root@localhost ~]# systemctl start docker

2、配置客户端信任http

由于从docker1.3.2版本开始,使用registry时,必须使用TLS保证其安全。我们不用https的话,需要在客户机中增加一个配置文件。

[root@localhost ~]# vim /etc/docker/daemon.json

{
        "registry-mirrors": ["http://172.168.1.249:5000"]
}

# 重启Docker

[root@localhost ~]# systemctl restart docker

3、客户端登录Harbor

[root@localhost ~]# docker login -u admin -p Harbor12345 172.168.1.249

WARNING! Using --password via the CLI is insecure. Use --password-stdin.

Error response from daemon: Get https://172.168.1.249/v2/: dial tcp 172.168.1.249:443: connect: connection refused

4、修改docker.service

# 查找docker.service 所在的位置

[root@localhost ~]# find / -name docker.service

[root@localhost ~]# vim /usr/lib/systemd/system/docker.service

# 在ExecStart后面加入--insecure-registry=172.168.1.249

5、重新启动服务

[root@localhost ~]# systemctl daemon-reload

[root@localhost ~]# systemctl reload docker

[root@localhost ~]# docker login -u admin -p Harbor12345 172.168.1.249

6、验证推送镜像

# pull镜像

[root@localhost ~]# docker pull hello-world

Using default tag: latest

latest: Pulling from library/hello-world

0e03bdcc26d7: Pull complete

Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9

Status: Downloaded newer image for hello-world:latest

docker.io/library/hello-world:latest

# 打标签

[root@localhost ~]# docker tag hello-world 172.168.1.249/library/hello-world:v1

# 推送到Harbor

[root@localhost ~]# docker push 172.168.1.249/library/hello-world:v1

The push refers to repository [172.168.1.249/library/hello-world]

9c27e219663c: Pushed

v1: digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 size: 525

7、查看Harbor

显示已经成功上传了。

8、删除本地的镜像,从Harbor上pull

# 查看本地镜像

[root@localhost ~]# docker images

REPOSITORY                                       TAG    IMAGE ID             CREATED             SIZE

172.168.1.249/library/hello-world    v1       bf756fb1ae65      5 months ago     13.3kB

hello-world                                         latest   bf756fb1ae65     5 months ago     13.3kB

# 删除本地镜像

[root@localhost ~]# docker rmi -f bf756fb1ae65

[root@localhost ~]# docker images

REPOSITORY        TAG         IMAGE ID         CREATED         SIZE

# 从Harbor上pull镜像

[root@localhost ~]# docker pull 172.168.1.249/library/hello-world:v1

v1: Pulling from library/hello-world

0e03bdcc26d7: Pull complete

Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042

Status: Downloaded newer image for 172.168.1.249/library/hello-world:v1

172.168.1.249/library/hello-world:v1

# 查看镜像

REPOSITORY                                          TAG    IMAGE ID            CREATED             SIZE

172.168.1.249/library/hello-world       v1      bf756fb1ae65      5 months ago     13.3kB

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
Wechat
微信扫一扫,加我!
weinxin
微信公众号
微信扫一扫,关注我!
weinxin
Docker最后更新:2024-1-24
小柒博客
  • 本文由 小柒博客 发表于 2020年6月24日15:38:36
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/7228.html
评论  2  访客  2
    • 匿名网友
      匿名网友 0

      不错。

      • 飒飒
        飒飒 0

        写的不错

      匿名

      发表评论

      匿名网友
      :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

      拖动滑块以完成验证