Docker 私有仓库 harbor 部署

发布时间: 更新时间: 总字数:539 阅读时间:2m 作者: 分享

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"]
}

重启docker服务

使用

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中可以看到。

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;
最新评论
加载中...
Home Archives Categories Tags