Harbor私有仓库搭建

警告
本文最后更新于 2022-07-01,文中内容可能已过时。

摘要

SoftwareVersion
Docker engineversion 17.06.0-ce+ 或者更高
Docker Composeversion 1.18.0 或者更高
Openssl最好是最新的

推荐使用pip安装docker-compose,因为pip可以为你自动对应版本问题

1
2
yum -y install epel-release
yum -y install python-pip

确认版本

1
pip --version

更新pip

1
pip install --upgrade pip

临时使用

可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple

例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple docker-compose,这样就会从清华这边的镜像去安装docker-compose。

永久修改,一劳永逸

Linux下,修改~/.pip/pip.conf(没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)

内容如下:

1
2
3
4
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
1
pip install docker-compose

查看版本

1
docker-compose version

下载页面

1
wget https://storage.googleapis.com/harbor-releases/release-1.9.0/harbor-offline-installer-v1.9.1.tgz

解压

1
tar xvf harbor-offline-installer-v1.9.1.tgz
1
2
cd harbor/
vi harbor.yml

修改

1
hostname = 192.168.0.2

这里只是简单的测试,所以只编辑这一行,其他的默认不做修改;可根据实际情况做修改!

配置docker私有仓库

因为docker默认使用的是https连接,而harbor默认使用http连接,所以需要修改docker配置标志insecure registry不安全仓库的主机。当然,harbor也可以设置为https

添加私有仓库地址

1
2
3
4
5
cat << EOF >>/etc/docker/daemon.json
{
    "insecure-registries": ["192.168.0.2"]
}
EOF

重启docker

1
2
systemctl daemon-reload
systemctl restart docker.service
1
./instsall.sh

安装Notary

要安装带有Notary服务的Harbor,请在运行时添加一个参数 install.sh:

1
./install.sh --with-notary

Note: 对于安装 Notary 这个参数 ui_url_protocol必须设置为 “https”. 要配置HTTPS,请参考以下部分.

更多关于Notary和Docker内容信任的信息,请参考 Docker’s documentation.

安装Clair

安装带有Clair service,添加参数当运行 install.sh:

1
./install.sh --with-clair

有关Clair的更多信息,请参阅Clair的文档

使用chart仓库

安装带有chart仓库服务的Harbor, 添加参数当你运行install.sh:

1
./install.sh --with-chartmuseum

Note:如果你都想安装Notary, Clair and chart repository service, 你必须同时指定

1
./install.sh --with-notary --with-clair --with-chartmuseum

会拉取好几个镜像下来,及检查环境:

https://img.bwcxtech.com/img/20200928154340.png

1
2
3
4
✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at https://harbor.qmerry.com. 
For more details, please visit https://github.com/vmware/harbor .

到这里基本就安装成功了!

安装完成后会生成如下6个容器:

1
docker ps

https://img.bwcxtech.com/img/20200928154243.png

6、验证

打开浏览器访问:http://192.168.0.2

https://img.bwcxtech.com/img/20200928154238.png

登录私有仓库

1
2
3
4
5
docker login 192.168.0.2
Username: admin
Password:	#(默认密码为:Harbor12345,可在harbor.yml文件中修改)

Login Succeeded
1
2
3
cd harbor
docker-compose down -v
# docker-compose stop
1
2
cd ..
mv harbor harbor_bak
1
2
wget https://github.com/goharbor/harbor/releases/download/v2.3.1/harbor-offline-installer-v2.3.1.tgz
tar xf harbor-offline-installer-v2.3.1.tgz
1
2
3
4
cd harbor
cp harbor.yml.tmpl harbor.yml
vi harbor.yml
./prepare # 更新配置文件

Harbor v2.1 及之前的版本内置了 Clair 镜像扫描器,在 v2.2 中,Harbor使用了 Aqua Trivy 作为缺省扫描器。Clair 作为可选组件,仍然可以安装使用。

安装带有Notary服务--with-notary

安装带有trivy服务--with-trivy

安装带有chart仓库服务--with-chartmuseum

其中Clair服务--with-clair已弃用

1
./install.sh --with-trivy