Harbor 是VMware公司开源的企业级Docker Registry 项目,项目地址:https://github.com/vmware/harbor
1.安装Docker
https://blog.csdn.net/a275109112/article/details/89094674
2.安装docker-compose
地址:https://docs.docker.com/compose/install/
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
或
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
3.下载离线安装包
yum -y install wget
wget http://harbor.orientsoft.cn/harbor-v1.5.0/harbor-offline-installer-v1.5.0.tgz
tar xvf harbor-offline-installer-v1.5.0.tgz
5.自签TLS证书
https://github.com/vmware/harbor/blob/master/docs/configure_https.md
证书存放路径 :/usr/local/bin/harbor/harbor/ssl
#创建证书目录 在harbor目录下创建ssl文件目录
mkdir -p /usr/local/bin/harbor/harbor/ssl
cd /usr/local/bin/harbor/harbor/ssl
# openssl genrsa -out ca.key 4096
#获取证书授权
# openssl req -x509 -new -nodes -sha512 -days 3650 \
-subj "/C=TW/ST=Taipei/L=Taipei/O=example/OU=Personal/CN=yourdomain.com" \
-key ca.key \
-out ca.crt
#获取服务器证书
#创建私钥
# openssl genrsa -out yourdomain.com.key 4096
#生成证书签名请求
# openssl req -sha512 -new \
-subj "/C=TW/ST=Taipei/L=Taipei/O=example/OU=Personal/CN=yourdomain.com" \
-key yourdomain.com.key \
-out yourdomain.com.csr
#生成注册表主机的证书
cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1=yourdomain.com
DNS.2=yourdomain
DNS.3=hostname
EOF
# openssl x509 -req -sha512 -days 3650 \
-extfile v3.ext \
-CA ca.crt -CAkey ca.key -CAcreateserial \
-in yourdomain.com.csr \
-out yourdomain.com.crt
执行完上面命令之后,生成如下文件:
[root@localhost ssl]# ls -l
total 28
-rw-r--r--. 1 root root 2029 Apr 11 16:49 ca.crt
-rw-r--r--. 1 root root 3247 Apr 11 16:48 ca.key
-rw-r--r--. 1 root root 17 Apr 11 16:50 ca.srl
-rw-r--r--. 1 root root 266 Apr 11 16:50 v3.ext
-rw-r--r--. 1 root root 2098 Apr 11 16:50 yourdomain.com.crt
-rw-r--r--. 1 root root 1704 Apr 11 16:49 yourdomain.com.csr
-rw-r--r--. 1 root root 3243 Apr 11 16:49 yourdomain.com.key
4.Harbor安装与配置
# vi harbor/harbor.cfg
修改:
hostname = yourdomain.com
ui_url_protocol = https
ssl_cert = /usr/local/bin/harbor/harbor/ssl/yourdomain.com.crt
ssl_cert_key = /usr/local/bin/harbor/harbor/ssl/yourdomain.com.key
secretkey_path = /usr/local/bin/harbor/harbor/ssl
#默认密码为:Harbor12345
harbor_admin_password = 12345
修改完harbor.cfg之后,执行
#准备
./prepare
#安装
./install.sh
#查看
docker-compose ps
#访问地址
https://yourdomain.com
如无法访问作如下操作:
修改C:\Windows\System32\drivers\etc\hosts
增加 192.168.88.121 yourdomain.com
账号:admin 密码:12345
页面如下:
在项目中标记镜像:
docker tag SOURCE_IMAGE[:TAG] yourdomain.com/test/IMAGE[:TAG]
推送镜像到当前项目:
docker push yourdomain.com/test/IMAGE[:TAG]
解释: yourdomain表示镜像仓库地址,test为项目,IMAGE表示镜像,:TAG 表示版本
6.Docker主机访问Harbor