Harbor简介
Harbor is an open source container image registry that secures images with role-based access control, scans images for vulnerabilities, and signs images as trusted. As a CNCF Incubating project, Harbor delivers compliance, performance, and interoperability to help you consistently and securely manage images across cloud native compute platforms like Kubernetes and Docker.
更多内容参考Harbor官网。
安装Harbor
前置条件
参考Harbor Installation Prerequisites
1、硬件需求
硬件最小需求:2C4G40G。
硬件推荐需求:4C8G160G。
2、软件需求
Docker engine,Version 17.06.0-ce+ or higher
Docker Compose,Version 1.18.0 or higher
Openssl,Latest is preferred
3、网络端口
444、4443和80
下载安装Harbor
1、访问Harbor releases page,下载需要的harbor版本,这里选择下载 harbor-offline-installer-v1.10.1.tgz
或者使用curl命令下载:
1 | curl -C - -O -L https://github.com/goharbor/harbor/releases/download/v1.10.1/harbor-offline-installer-v1.10.1.tgz |
2、解压
1 | tar -xzvf harbor-offline-installer-v1.10.1.tgz |
3、配置harbor.yml
安装前修改harbor.yaml,参考Configure the Harbor YML File,按需要修改如下几个字段:
1 | # The IP address or hostname to access admin UI and registry service. |
4、执行安装./install.sh
如果安装完成发现配置错误,可以修改配置后再次执行脚本。
如果报错 ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule ,那么重启docker后再次执行脚本。
至此,harbor安装完成,没有配置https。
验证安装
浏览器验证
浏览器访问 http://192.168.56.200 ,可以看到harbor登录页面。
输入用户名密码,admin和Harbor12345,登录harbor控制台。
命令行验证
1 | docker ps |
输入用户名密码,admin和Harbor12345,登录报错:
Error response from daemon: Get https://192.168.56.200/v2/: dial tcp 192.168.56.200:443: connect: connection refused。
这是因为,docker1.3.x之后与registry交互,默认使用https协议。
修改/etc/docker/daemon.json,添加insecure-registries参数:
1 | { |
然后重启docker:
1 | systemctl daemon-reload |
重新登录,成功。
使用
启动和停止
1、停止docker-compose down -v
2、修改配置
修改harbor.yml后,执行./prepare
3、启动docker-compose up -d
上传镜像
1 | docker pull busybox:1.31 |
报错:
The push refers to repository [harbor.voidking.com/voidking/busybox]
a6d503001157: Preparing
denied: requested access to the resource is denied
这是因为,需要先创建项目。在web控制台创建项目 voidking,再次上传,成功。带有subpath的镜像,同样可以上传成功。
下载镜像
1 | docker pull harbor.voidking.com/voidking/busybox:1.31 |
高可用
如果搭建高可用harbor,比如搭建两个实例的harbor,那么需要XSRFKey保持一致,在 common/config/core/app.conf 中配置。