Harbor 是 Docker 企业级镜像仓库,今天就在我的 ubuntu 18.04 上 安装 一下,这玩意难装死了,花费了我大半天的时间。
我的安装环境
vmware 虚拟机: ubuntu sever 18.04, 内存6G
Docker版本: Docker version 20.10.2, build 20.10.2-0ubuntu1~18.04.2
docker-compose版本:docker-compose version 1.29.2, build 5becea4c
下载的harbor 离线安装包: harbor-offline-installer-v2.2.2.tgz
安装过程
解压 harbor-offline-installer-v2.2.2.tgz 并 cd进去
这里有一个配置文件 harbor.yml (如果没有就把 harbor.yml.tmpl 复制一份 ),需要编辑:
- # The IP address or hostname to access admin UI and registry service.
- # DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
- hostname: harbor.xiaxudong.com
- # http端口号,我们用 https连接,这里就随便配吧
- http:
- # port for http, default is 80. If https enabled, this port will redirect to https port
- port: 9090
- #https related config
- https:
- # https port for harbor, default is 443
- port: 443
- # The path of cert and key files for nginx
- # 这里是 https 需要的 密钥 等信息
- certificate:/home/ki/encrypt/privkey.pem
- private_key: /home/ki/encrypt/privkey.pem
看网上说,harbor 也支持http 连接,需要在 /etc/docker/daemon.json 或者 docker.service 配置 insecure-registries ,
我试了很多遍,不行,所以还是使用https吧。
但是https 需要 ssl证书信息,我们是在虚拟机里配,不是公网,所以要 自签证书,
根据 网上 大部分的openssl 自签证书配置,均失败,
而且这里有个问题,就是即使自签证书成功,你在其他虚拟机上连接的时候也要导入自制证书,太麻烦。
ssl 解决方案:
我的博客域名是 xiaxudong.com, 我可以在 Let’s encrypt 上申请 *.xiaxudong.com的证书,然后复制到本地虚拟机,
本地虚拟机可以联网,配置 harbor.xiaxudong.com 的 hosts 后即可 https 访问本地的 harbor 。
申请证书参考:
https://qizhanming.com/blog/2019/04/23/how-to-install-let-s-encrypt-wildcards-certificate-on-centos-7
我在博客的公网机器上申请好证书,拷贝到以下目录:
/home/ki/encrypt/privkey.pem
/home/ki/encrypt/privkey.pem
然后 编辑 harbor.yml 的证书相关配置如上即可。
在每个需要访问 harbor仓库的机器上 编辑hosts:
- 10.2.156.97 harbor.xiaxudong.com #10.2.156.97 是 harbor 虚拟机ip
执行安装
- ./install.sh
在浏览器中访问 harbor.xiaxudong.com 即可。