Harbor 容器镜像仓库
Harbor仓库概述
Docker官方提供了Registry镜像仓库,但是Registry的功能相对简陋。Harbor是VMware公司提供的一款镜像仓库,提供了权限控制、分布式发布、强大的安全扫描与审查机制等功能. Harbor 私有仓库,它以 Registry 为基础,提供了对用户友好的管理界面,可以帮助我们快速搭建⼀个企业级的 Docker Registry服务。Harbor 的每个组件都是以 Docker 容器的形式构建的,使用 Docker Compose 进行部署。 |
Harbor优势
|
Harbor环境准备
主机名 | IP地址 | 系统版本 | 硬件配置 |
---|---|---|---|
harbor | 10.10.20.129 | CentOS 8-Stream | 2C/4G |
安装docker
#配置阿里云docker-ce镜像源,先安装一些必要的系统工具
[root@harbor ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
#添加软件源信息
[root@harbor ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@harbor ~]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
#更新缓存并安装Docker-CE
[root@harbor ~]# yum makecache
[root@harbor ~]# yum -y install docker-ce
#查看docker版本
[root@harbor ~]# docker --version
Docker version 24.0.4, build 3713ee1
安装docker-compose
harbor通过docker-compose进⾏管理,需要提前下载docker-compose⼆进制⽂件
#github下载docker-compose
[root@harbor ~]# wget https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-linux-x86_64
#移动⼆进制⽂件到/usr/bin⽬录,并更名为docker-compose
[root@harbor ~]# mv docker-compose-linux-x86_64 /usr/bin/docker-compose
#赋予docker-compose可执行权限
[root@harbor ~]# chmod +x /usr/bin/docker-compose
#查看docker-compse版本
[root@harbor ~]# docker-compose --version
Docker Compose version v2.20.0
下载Harbor(v2.8.2)
地址:https://github.com/goharbor/harbor/releases/tag/v2.8.2
#下载harbor
[root@harbor ~]# wget https://github.com/goharbor/harbor/releases/download/v2.8.2/harbor-offline-installer-v2.8.2.tgz
#解压
[root@harbor ~]# tar xf harbor-offline-installer-v2.8.2.tgz -C ./
#复制一份配置文件
[root@harbor ~]# cd harbor
[root@harbor harbor]# cp harbor.yml.tmpl harbor.yml
#修改配置文件
[root@harbor harbor]# vim harbor.yml
hostname: 10.10.20.129 #指定Harbor主机地址
http: #访问⽅式为http(不⽤修改)
port: 80 #默认端⼝(不⽤修改)
#https: #注释这一行,这一行是https访问⽅式(需要证书才可以使⽤)
#port: 443 #注释这一行
#certificate: /your/certificate/path #注释证书⽂件
#private_key: /your/private/key/path #注释证书⽂件
harbor_admin_password: 111111 #设置访问密码,可自行修改
启动docker,设置开机自启
[root@harbor ~]# systemctl enable --now docker
执行harbor脚本安装
#执⾏预备脚本,下载harbor所需的镜像⽂件(在harbor目录下执行)
[root@harbor ~]# cd harbor
[root@harbor harbor]# ./prepare
#执⾏安装脚本(在harbor目录下执行)
[root@harbor harbor]# ./install.sh
.....
✔ ----Harbor has been installed and started successfully.---- #成功即可
#验证运⾏情况
[root@harbor ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
863643822bd8 goharbor/harbor-jobservice:v2.8.2 "/harbor/entrypoint.…" About a minute ago Up About a minute (healthy) harbor-jobservice
061253b486ad goharbor/nginx-photon:v2.8.2 "nginx -g 'daemon of…" About a minute ago Up About a minute (healthy) 0.0.0.0:80->8080/tcp, :::80->8080/tcp nginx
bdf2a6d90820 goharbor/harbor-core:v2.8.2 "/harbor/entrypoint.…" About a minute ago Up About a minute (healthy) harbor-core
5a3bd54f0ba1 goharbor/harbor-registryctl:v2.8.2 "/home/harbor/start.…" About a minute ago Up About a minute (healthy) registryctl
425bb7851b1f goharbor/registry-photon:v2.8.2 "/home/harbor/entryp…" About a minute ago Up About a minute (healthy) registry
86df3dc32587 goharbor/redis-photon:v2.8.2 "redis-server /etc/r…" About a minute ago Up About a minute (healthy) redis
9ff8ffd86490 goharbor/harbor-db:v2.8.2 "/docker-entrypoint.…" About a minute ago Up About a minute (healthy) harbor-db
66a47caad0d2 goharbor/harbor-portal:v2.8.2 "nginx -g 'daemon of…" About a minute ago Up About a minute (healthy) harbor-portal
ecf3f91416ee goharbor/harbor-log:v2.8.2 "/bin/sh -c /usr/loc…" About a minute ago Up About a minute (healthy) 127.0.0.1:1514->10514/tcp harbor-log
访问harbor UI界面:10.10.20.129
用户名:admin 密码:111111 (前面配置文件设置的密码)
创建⼀个image仓库⽤于存储镜像
点击【新建项⽬】,【访问级别】不勾选【公开】就是私有仓库,反之则是公有仓库,【项目配额限制】中【-1】即为不限制存储容量
配置指定harbor仓库地址
#顺带把镜像加速配一下,使用的是阿里的
[root@harbor ~]# vim /etc/docker/daemon.json
{ "registry-mirrors": ["https://00ry8okw.mirror.aliyuncs.com"],
"insecure-registries": ["http://10.10.20.129"]
}
#停⽌harbor,注意要先进入harbor目录才能执行docker-compose down
[root@harbor ~]# cd harbor
[root@harbor harbor]# docker-compose down
#保存配置
[root@harbor harbor]# systemctl daemon-reload
#重启docker
[root@harbor harbor]# systemctl restart docker
#重启harbor,同上,要在harbor目录下执行
[root@harbor harbor]# docker-compose up -d
镜像上传到Harbor仓库
#下载镜像(nginx等)镜像并上传到harbor仓库
[root@harbor ~]# docker pull nginx
[root@harbor ~]# docker images
#登录到harbor仓库上传镜像
[root@harbor ~]# docker login 10.10.20.129
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
#给nginx镜像打标签,后面跟地址,仓库名和标签名
[root@harbor ~]# docker tag nginx:latest 10.10.20.129/image/nginx:v1.0
#推送镜像到Harbor的image仓库
[root@harbor ~]# docker push 10.10.20.129/image/nginx:v1.0