一、什么是Harbor
Harbor是一个用于存储和分发Docker镜像的企业级Registry
服务器,
由VMware公司开源的企业级docker registry
服务器。docker官方也有提供的Registry
服务器,但是要收费,所以我们使用开源的Harbor
管理镜像。
二、为什么要用Harbor
当有自定义镜像的需求的时候使用。
三、配置Harbor
github下载release版本gz包并上传至服务器,解压缩。
tar -zxvf harbor-offline-installer-v2.2.2.tgz
# 输出如下
harbor/harbor.v2.2.2.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl
修改配置文件
# 复制默认模版文件 harbor.yml.tmpl 并重命名为 harbor.yml
cp harbor.yml.tmpl harbor.yml
vi harbor.yml.tmpl
# 修改为域名或你服务器 IP
hostname: 192.168.109.132
# yml里面可以看到harbor的初始化密码
harbor_admin_password: Harbor12345
执行安装脚本
./install.sh
可能出现的问题
- 安装Docker harbor报错:ERROR:root:Error: The protocol is https but attribute ssl_cert is not set
解决办法: 注释以下配置
- 80端口被gitlab安装的nginx占用,错误信息:
1146780700a24f3cbbfaf919832cf5b3e3734c579a): Bind for 0.0.0.0:80 failed: port is already allocated
ERROR: for proxy Cannot start service proxy: driver failed programming external connectivity on endpoint nginx (6c10287fb7f7570ccbcd961146780700a24f3cbbfaf919832cf5b3e3734c579a): Bind for 0.0.0.0:80 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
解决办法: 修改gitlab nginx的端口为8080
修改问题后重启,登录验证
- /usr/local/docker/harbor执行docker-compose up -d重新启动程序
- 启动登录harbor后台验证,http://192.168.109.132/
配置客户端
在/etc/docker/daemon.json
中增加如下内容(如果文件不存在请新建改文件)
{
"registry-mirrors": [
"https://registry.docker-cn.com"
],
"insecure-registries": [
"192.168.109.132"
]
}
registry-mirrors之前配置过阿里的镜像源,这里主要是新增镜像私服地址insecure-registries
重启服务
systemctl daemon-reload
systemctl restart docker
检查客户端配置是否生效
使用docker info
命令手动检查,如果从配置中看到如下内容,说明配置成功
Insecure Registries:
192.168.109.132
127.0.0.0/8
推送项目
- 创建项目myshop
- 执行命令推送镜像到harbor
# 在项目中标记镜像(这里以nginx镜像为例子)
docker tag nginx:latest 192.168.109.132/myshop/nginx:latest
# 登录 Harbor
docker login 192.168.109.132 -u admin -p Harbor12345
# 推送镜像到项目myshop
docker push 192.168.109.132/myshop/nginx:latest
-
查看镜像
-
从harbor拉取镜像
# 登录
docker login 192.168.109.132 -u admin -p Harbor12345
# 拉去镜像
docker pull 192.168.109.132/myshop/nginx:latest