Harbor是由VMware公司开源的企业级的Docker Registry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能。
安装Docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
# 优化内核
sudo tee -a /etc/sysctl.conf <<-EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl -p
# 启动
systemctl start docker.server
安装docker-compose
到https://github.com/docker/compose/releases
下载安装包安装
curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version
安装Harbor
源码:https://github.com/vmware/harbor/releases
wget https://github.com/goharbor/harbor/releases/download/v2.1.0/harbor-offline-installer-v2.1.0.tgz
tar -zxvf harbor-offline-installer-v2.1.0.tgz
cp harbor.yml.tmpl harbor.yml
修改harbor.yml
,包括:
hostname: hub.xiexianbin.cn
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 80
# https related config
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /your/certificate/path
private_key: /your/private/key/path
启动:
./install.sh
配置
使用
客户端配置
由于docker
仓库默认使用https
,而harbor
默认使用http
,需要在客户端修改/etc/docker/daemon.json
:
{
"insecure-registries": ["hub.xiexianbin.cn"],
"registry-mirrors": ["http://hub.xiexianbin.cn"]
}
重启docker
服务,参数说明:
insecure-registries
使用非SSL模式registry-mirrors
镜像的仓库,通过该参数pull镜像时,不需要加 hub.xiexianbin.cn
的前缀
使用
docker pull alpine:latest
docker tag alpine:latest hub.xiexianbin.cn/library/alpine:latest
docker login hub.xiexianbin.cn
docker push hub.xiexianbin.cn/library/alpine:latest
PS:认证信息在~/.docker/config.json
中可以看到。
harbor 角色说明
系统级角色
Harbor 系统管理员
匿名用户
无权私有项目访问权限,支持对公共项目的只读访问权限
用户角色
受限访客(Limited Guest)
受限访客没有项目的完全读取权限访客(Guest)
Pubilc 仓库的只读权限开发者(Developer)
指定项目的读写权限维护者(Master)
拥有开发者
的所有权限,还包括扫描镜像、删除镜像、查看复制作业和helm charts的能力项目管理员(Project Admin)
项目级的管理权限
参考
FAQ
nginx代理问题
错误日志:
# docker push hub.xiexianbin.cn/x/alpine:latest
The push refers to a repository [hub.xiexianbin.cn/x/alpine] (len: 1)
...
unauthorized: authentication required
解决方法:
nginx代理中加入
proxy_set_header X-Forwarded-Proto https;