Harbor是由VMware公司提供的开源的、企业级的Docker Registry管理项目。它不仅提供友好的UI界面,同时还支持权限管理(RBAC)、LDAP、日志审核、自我注册、镜像复制等功能。相比Docker官方提供的registry仓库,harbor提供了更加安全可靠的服务,更适合生产环境和大项目中使用。
Docker安装:Docker安装部署详见上一篇Docker安装博文:https://blog.csdn.net/weixin_42516922/article/details/118932739
# Github源
[root@localhost ~]# curl -L https://github.com/docker/compose/releases/download/1.26.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# Daocloud国内源 (推荐)
[root@localhost ~]# curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# 赋予执行权限
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose
[root@localhost ~]# yum install epel-release -y
[root@localhost ~]# yum install python-pip -y
[root@localhost ~]# pip --version
[root@localhost ~]# pip install --upgrade pip
[root@localhost ~]# pip install -U -i https://pypi.tuna.tsinghua.edu.cn/simple docker-compose
[root@localhost ~]# docker-compose version
docker-compose version 1.26.0, build d4451659
docker-py version: 4.2.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
# 在线安装包
[root@localhost ~]# wget https://github.com/goharbor/harbor/releases/download/v2.3.0/harbor-online-installer-v2.3.0.tgz
[root@localhost ~]# tar xvf harbor-online-installer-v2.3.0.tgz
# 离线安装包 (推荐安装方式)
[root@localhost ~]# wget https://github.com/goharbor/harbor/releases/download/v2.3.0/harbor-offline-installer-v2.3.0.tgz
[root@localhost ~]# tar xvf harbor-offline-installer-v2.3.0.tgz
[root@localhost harbor]# vim harbor.yml
# 访问地址,可以配置为域名,IP;但不能用127.0.0.1或localhost。
hostname: harbor.xxx.com
# http协议配置,默认端口:80
http:
port: 80
# https配置,如需启用去掉注释即可,需要提供证书。
#https:
# port: 443
# certificate: /your/certificate/path
# private_key: /your/private/key/path
# 启动Harbor后,web管理员的密码,默认是:Harbor12345
harbor_admin_password: Harbor12345
# Harbor 内置数据库配置
database:
# 默认密码为:root123
password: root123
# 数据存储目录
data_volume: /data/harbor-data/
# 日志信息配置
log:
level: info
local:
rotate_count: 50
rotate_size: 200M
# 指定日志存储目录
location: /var/log/harbor
[root@localhost harbor]# ./prepare
[root@localhost harbor]# ./install.sh
[root@localhost harbor]# docker-compose down
# 后台启动
[root@localhost harbor]# docker-compose up -d
[root@localhost harbor]# docker-compose images
Container Repository Tag Image Id Size
----------------------------------------------------------------------------------------------------------
harbor-core goharbor/harbor-core v1.10.0 f3a3065b3af2 128.4 MB
harbor-db goharbor/harbor-db v1.10.0 634404a417cf 148 MB
harbor-jobservice goharbor/harbor-jobservice v1.10.0 d6d4f2b125f6 141.9 MB
harbor-log goharbor/harbor-log v1.10.0 fb15f6772e9a 82.29 MB
harbor-portal goharbor/harbor-portal v1.10.0 fbaeb1fdacad 52.09 MB
nginx goharbor/nginx-photon v1.10.0 f7ed614c3abc 43.99 MB
redis goharbor/redis-photon v1.10.0 6df66e5c1ca7 110.9 MB
registry goharbor/registry-photon v2.7.1-patch-2819-2553-v1.10.0 2115e08fa399 86.51 MB
registryctl goharbor/harbor-registryctl v1.10.0 c550280445e6 103.8 MB
docker tag SOURCE_IMAGE[:TAG] harbor.xxx.com/test/IMAGE[:TAG]
docker push harbor.xxx.com/test/IMAGE[:TAG]
例:
[root@localhost ~]# docker tag nginx harbor.haier.com/test/nginx:latest
# 镜像上传之前需要对Docker进行配置,对http协议进行新人
[root@localhost ~]# vim /etc/docker/daemon.json
{ "insecure-registries":["harbor.haier.com"] }
# 重启docker
[root@localhost ~]# systemctl daemon-reload && systemctl restart docker
# 登录仓库并进行推送镜像
[root@localhost ~]# docker login harbor.haier.com
[root@localhost ~]# docker push harbor.haier.com/test/nginx:latest
需要安装jq命令
[root@localhost ~]# yum install -y jq
# 仓库迁移脚本
#!/bin/sh
source_registry=IP:5000
target_registry=harbor.xxx.com/test #注意最后不要带 /
image_names=`curl -u username:password http://$source_registry/v2/_catalog 2>/dev/null|jq .repositories[]|tr -d '"'`
for i in $image_names
do
tags=`curl -u username:password http://$source_registry/v2/$i/tags/list 2>/dev/null|jq ".tags[]"|tr -d '"'`
for j in $tags
do
docker pull $source_registry/$i:$j
docker tag $source_registry/$i:$j $target_registry/$i:$j
docker push $target_registry/$i:$j
done
done
附:Docker-compose常用命令参见我的另一篇博文:Docker-compose常用命令总结