安装docker,git

yum install docker  docker-logrotate git -y

安装docker-compose

yum install python-virtualenv -yvirtualenv ven_harborsource ven_harbor/bin/activatepip install --upgrade pippip install docker-compose

下载harbor

wget https://github.com/vmware/harbor/releases/download/0.4.1/harbor-offline-installer-0.4.1.tgztar xvzf harbor-offline-installer-0.4.1.tgz

生成自签名证书

mkdir cacd caopenssl req \    -newkey rsa:4096 -nodes -sha256 -keyout ca.key \    -x509 -days 365 -out ca.crtopenssl req \    -newkey rsa:4096 -nodes -sha256 -keyout yourdomain.com.key \    -out yourdomain.com.csrtouch  /etc/pki/CA/index.txtecho '01' > /etc/pki/CA/serialopenssl ca -in yourdomain.com.csr -out yourdomain.com.crt -cert ca.crt -keyfile ca.key -outdir .# 如果打算使用IP方式访问registry,请将上面命令替换为如下命令,your_ip,为harbor所在的服务器的IP,# 默认情况下,https仅支持域名访问,若使用上面的命令进行签名,执行docker login your_ip,会有如下报错# Failed to tls handshake with x.x.x.x x509: cannot validate certificate for x.x.x.x because it doesn't contain any IP SANsecho subjectAltName = IP:your_ip > extfile.cnfopenssl ca -in your_ip.csr -out your_ip.crt -cert ca.crt -keyfile ca.key -extfile extfile.cnf -outdir .

安装harbor

cd harbor/config/nginxcp ~/ca/yourdomain.com.crt cert/cp ~/ca/yourdomain.com.key cert/mv nginx.conf nginx.conf.bakcp nginx.https.conf nginx.confsed -i s/harbordomain.com/yourdomain.com/g nginx.confsed -i s/harbordomain/yourdomain.com/g nginx.conf# 编辑 ~/harbor/harbor.cfghostname = yourdomain.comui_url_protocol = httpsharbor_admin_password = Harbor12345auth_mode = db_authdb_password = root123# 安装harbor./install.sh

配置client

  • 将-insecure-registry从docker配置文件中移除,重启docker

  • 复制ca.crt到client

mkdir -p /etc/docker/certs.d/yourdomain.comcp ca.crt /etc/docker/certs.d/yourdomain.com

创建项目

  • 使用http://yourdomain.com 登录 harbor,会自动重定向到 https://yourdomain.com

  • 创建项目test

将镜像推送到harbor中

docker login yourdomain.comdocker tag centos:7 yourdomain.com/test/centos:7docker push yourdomain.com/test/centos:7

参考链接: