安装Harbor私有仓库_超详细
Harbor官网:https://goharbor.io/
标准的Harbor安装过程包括以下几个步骤:
1、请确保目标主机满足Harbor安装前提条件;
2、下载Harbor安装程序;
3、配置港口HTTPS访问;
4、配置Harbor YML文件;
5、配置启用内部TLS;
6、运行安装程序脚本
Harbor安装前提条件
Harbor被部署为几个Docker容器。因此,您可以在任何支持Docker的Linux发行版上部署它。目标主机需要安装Docker,并安装Docker Compose。
硬件
CPU最小两核,推荐四核,
内存最小4G,推荐8G,
硬盘最小40G,推荐160G。
下载安装包
Docker Compose介绍 https://docs.docker.com/compose/
Docker Compose安装,下载Docker Compose安装包:
wget https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-linux-x86_64
也可以使用浏览器下载:https://github.com/docker/compose/releases
# mv docker-compose-linux-x86_64 /usr/bin/docker-compose # chmod +x /usr/bin/docker-compose # docker-compose version Docker Compose version v2.15.1
Harbor安装包分为在线和离线安装包两个。下载地址:https://github.com/goharbor/harbor/releases/
选择版本v2.5.5,如图:
wget https://github.com/goharbor/harbor/releases/download/v2.5.5/harbor-offline-installer-v2.5.5.tgz
解压
tar -zxvf harbor-offline-installer-v2.5.5.tgz -C /root
解压后生成一个harbor目录,目录内容如下:
配置
将配置文件harbor.yml.tmpl重新命名为harbor.yml,修改如下配置:
# cp harbor.yml.tmpl harbor.yml
# vim harbor.yml
hostname: 192.168.61.133 #本地地址 #certificate: /your/certificate/path #注释 #private_key: /your/private/key/path #注释 harbor_admin_password: Harbor12345 #登录密码
# ./prepare #可以不执行
prepare base dir is set to /root/harbor
WARNING: IPv4 forwarding is disabled. Networking will not work.
ERROR:root:Error: The protocol is https but attribute ssl_cert is not set
Error happened in config validation...
如果报错,注释掉上面https相关证书配置。
# ./install.sh #安装
成功后如图:
镜像上传下载
新建vim /etc/docker/daemon.json文件:
内容如下:
{ "insecure-registries":["192.168.61.133"] }
重新启动docker
[root@localhost harbor]# systemctl restart docker.service
进入harbor安装目录下
[root@localhost ~]# cd /root/harbor/
[root@localhost harbor]#
执行如下命令,启动harbor相关容器:
# docker-compose up -d
全部启动成功后,如图:查看harbor相关容器启动情况(总计9个):
[root@localhost harbor]# docker ps -a
容器启动后访问 http://192.168.61.133
执行如下命令,关闭harbor相关容器:
# docker-compose down #不需要执行
上传镜像
以redis镜像为例。下载redis镜像:
[root@localhost harbor]# docker pull redis:5.0.10
给拉取下来的redis镜像打tag:
# docker tag redis:5.0.10 192.168.61.133/library/redis:5.0.10
注:192.168.61.133/library/redis:5.0.10 表示 ip+项目名称+标签
不按这种格式tag后面会报错
登录仓库
账号:admin
密码:Harbor12345
[root@localhost harbor]# docker login 192.168.61.133 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 [root@localhost harbor]#
如下命令,上传192.168.61.133/library/redis:5.0.10镜像
[root@localhost harbor]# docker push 192.168.61.133/library/redis:5.0.10
浏览器登录Harbor查看:
尝试从Harbor拉取镜像
先删除本地的192.168.61.133/library/redis:5.0.10镜像
[root@localhost harbor]# docker rmi 192.168.61.133/library/redis:5.0.10
执行如下命令,拉取192.168.61.133/library/redis:5.0.10,如图:
[root@localhost harbor]# docker pull 192.168.61.133/library/redis:5.0.10
希望对您有所帮助