企业级镜像仓库harbor搭建(http/https)及使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了企业级镜像仓库harbor搭建(http/https)及使用相关的知识,希望对你有一定的参考价值。

1.Habor简介
Habor是由VMWare公司开源的容器镜像仓库。事实上,Habor是在Docker Registry上进行了相应的企业级扩展,从而获得了更加广泛的应用,这些新的企业级特性包括:管理用户界面,基于角色的访问控制,AD/LDAP集成以及审计日志等,足以满足基本企业需求。
2.安装docker-ce
1)安装依赖包
[[email protected] opt]# yum install -y yum-utils device-mapper-persistent-data lvm2
2)下载docker-ce 仓库
[[email protected] opt]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
官方比较慢的话,可以使用阿里云的docker-ce.repo
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3)更新仓库
yum repolist 或者 yum makecache fast
4)安装docker-ce
[[email protected] opt]# yum install docker-ce -y
5)配置加速并启动
[[email protected] opt]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
[[email protected] opt]# systemctl start docker
6) 确认安装完成
[[email protected] opt]# docker-compose version
技术分享图片
3.安装docker-compose
第一种方式:yum 安装
[[email protected] opt]# yum install docker-compose -y
第二种方式:下载可执行文件:
[[email protected] opt]# curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
[[email protected] opt]# chmod +x /usr/local/bin/docker-compose
确认安装完成:
技术分享图片
4.安装harbor
[[email protected] opt]# cd /opt
[[email protected] opt]# wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.6.1.tgz
[[email protected] opt]# tar -xf harbor-offline-installer-v1.6.1.tgz
[[email protected] opt]# cd harbor/
[[email protected] opt]# vim harbor.cfg
hostname = reg.slito.com harbor的服务地址(ip或者域名)
ui_url_protocol = http 选择http方式
harbor_admin_password = 123456 harbor web访问的密码
[[email protected] harbor]# ./prepare 加载配置
技术分享图片
[[email protected] harbor]# ./install.sh 安装harbor
技术分享图片
安装完成后,提示通过“ http://reg.slito.com” 访问harbor,用户名是admin,密码是之前设置的123456
技术分享图片
5.上传镜像到harbor仓库
在本机配置harbor仓库http可信
/etc/docker/daemon.json中添加“"insecure-registries":["reg.slito.com"]”,重启docker
技术分享图片
不然会报错,默认是走https的
技术分享图片
在node1上登录harbor仓库,上传/下载镜像
[[email protected] ~]# docker login reg.slito.com
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[[email protected] ~]# docker tag busybox reg.slito.com/library/busybox:v1
[[email protected] ~]# docker push reg.slito.com/library/busybox:v1
The push refers to repository [reg.slito.com/library/busybox]
8a788232037e: Pushed
v1: digest: sha256:915f390a8912e16d4beb8689720a17348f3f6d1a7b659697df850ab625ea29d5 size: 527
[[email protected] ~]#
在harbor中查看
技术分享图片
6.下载harbor中的镜像
先删掉原来的镜像
[[email protected] ~]# docker rmi reg.slito.com/library/busybox:v1
重新从harbor pull
[[email protected] ~]# docker pull reg.slito.com/library/busybox:v1
确认
[[email protected] ~]# docker images | grep busybox
reg.slito.com/library/busybox v1 59788edf1f3e 8 weeks ago 1.15MB

7.配置https访问
1) 安装openssl
#yum install openssl -y
2) 创建证书的database文件index.txt和序列文件serial
[[email protected] opt]# touch /etc/pki/CA/index.txt
[[email protected] opt]# echo "01" > /etc/pki/CA/serial
技术分享图片

3) 创建私钥,生成自签证书(用于发放给个人用户)
#(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem)
#openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem
技术分享图片
4) 客户端生成证书请求(.csr)
#cd /opt/harbor
#mkdir ssl
#cd ssl
#(umask 077;openssl genrsa -out reg.slito.com.key) 生成私钥
#openssl req -new -key reg.slito.com.key -out reg.slito.com.csr 生成证书请求
和上面cacert.pem生成时写的结果保持一致
技术分享图片
5) 签发证书(本机是CA同时又是申请证书的客户端)
#cd /opt/harbor/ssl
#openssl ca -in reg.slito.com.csr -out reg.slito.com.crt -days 365
技术分享图片
技术分享图片
6) 修改配置文件,重新启动harbor
#cd /opt/harbor
#docker-compose down -v
#vim harbor.cfg
ui_url_protocol = https
ssl_cert = ./ssl/reg.slito.com.crt
ssl_cert_key = ./ssl/cert/reg.slito.com.key
secretkey_path = ./ssl/
#./prepare
#./install.sh
技术分享图片
访问“https://reg.slito.com
技术分享图片
7) 其他主机访问harbor,pull/push镜像设置
拷贝reg.slito.com.crt到需要访问harbor仓库的主机上(/etc/docker/certs.d/reg.slito.com/),目标主机不用配置信任就可以直接访问。
#cp /opt/harbor/ssl/reg.slito.com.crt /etc/docker/certs.d/reg.slito.com/
技术分享图片

其他:关于https访问,可以看另一篇博客http://blog.51cto.com/slitobo/1931603

以上是关于企业级镜像仓库harbor搭建(http/https)及使用的主要内容,如果未能解决你的问题,请参考以下文章

使用Harbor搭建企业级私有docker仓库

docker进阶-搭建私有企业级镜像仓库Harbor

离线方式对企业级容器镜像仓库Harbor进行搭建

企业级镜像仓库harbor搭建(http/https)及使用

基于 Harbor 搭建 Docker 私有镜像仓库

Docker--------Harbor registry私有仓库搭建 [ Http ]