Harbor仓库搭建

Harbor

无论是使用Docker-distribution去自建仓库,还是通过官方镜像跑容器的方式去自建仓库,通过前面的演示我们可以发现其是非常的简陋的,还不如直接使用官方的Docker Hub去管理镜像来得方便,至少官方的Docker Hub能够通过web界面来管理镜像,还能在web界面执行搜索,还能基于Dockerfile利用Webhooks和Automated Builds实现自动构建镜像的功能,用户不需要在本地执行docker build,而是把所有build上下文的文件作为一个仓库推送到github上,让Docker Hub可以从github上去pull这些文件来完成自动构建。

但无论官方的Docker Hub有多强大,它毕竟是在国外,所以速度是最大的瓶颈,我们很多时候是不可能去考虑使用官方的仓库的,但是上面说的两种自建仓库方式又十分简陋,不便管理,所以后来就出现了一个被 CNCF 组织青睐的项目,其名为Harbor。

Harbor简介

Harbor是由VMWare在Docker Registry的基础之上进行了二次封装,加进去了很多额外程序,而且提供了一个非常漂亮的web界面。
Harbor简介
Harbor是由VMWare在Docker Registry的基础之上进行了二次封装,加进去了很多额外程序,而且提供了一个非常漂亮的web界面。

Project Harbor is an open source trusted cloud native registry project that stores, signs, and scans context.

Harbor extends the open source Docker Distribution by adding the functionalities usually required by users such as security, identity and management.

Harbor supports advanced features such as user management, access control, activity monitoring, and replication between instances.

Harbor的功能
Feathers:

  • Multi-tenant content signing and validation Security and
  • vulnerability analysis Audit logging Identity integration and
  • role-based access control Image replication between instances
  • Extensible API and graphical UI Internationalization(currently
  • English and Chinese)

Docker compose

Harbor在物理机上部署是非常难的,而为了简化Harbor的应用,Harbor官方直接把Harbor做成了在容器中运行的应用,而且这个容器在Harbor中依赖类似redis、mysql、pgsql等很多存储系统,所以它需要编排很多容器协同起来工作,因此VMWare Harbor在部署和使用时,需要借助于Docker的单机编排工具(Docker compose)来实现。

  • Compose is a tool for defining and running multi-container Docker
    applications. With Compose, you use a YAML file to configure your
    application’s services. Then, with a single command, you create and
    start all the services from your configuration.

Docker Compose官方文档

https://docs.docker.com/compose/

Harbor部署

Harbor官方文档

https://github.com/goharbor/harbor

#已经安装docker有docker仓库
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo  docker-ce.repo
#需要有这个docker-ce.repo

#安装要撰写 CLI 插件
[root@localhost ~]# DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
[root@localhost ~]# mkdir -p $DOCKER_CONFIG/cli-plugins
[root@localhost ~]# curl -SL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
[root@localhost ~]# cd .docker/cli-plugins/
[root@localhost cli-plugins]# ls
docker-compose
[root@localhost cli-plugins]# chmod +x docker-compose
[root@localhost cli-plugins]# ll
total 25188
-rwxr-xr-x. 1 root root 25792512 Aug 11 19:23 docker-compose
[root@localhost cli-plugins]# 
[root@localhost cli-plugins]# pwd
/root/.docker/cli-plugins
[root@localhost cli-plugins]# ln -s /root/.docker/cli-plugins/docker-compose /usr/bin/
[root@localhost cli-plugins]# cd 
[root@localhost ~]# which docker-compose 
/usr/bin/docker-compose
[root@localhost ~]# docker-compose version
Docker Compose version v2.7.0
[root@localhost ~]# 

//下载Harbor仓库
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget https://github.com/goharbor/harbor/releases/download/v2.5.3/harbor-offline-installer-v2.5.3.tgz

//解压到相应目录
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
harbor-offline-installer-v2.5.3.tgz
[root@localhost src]# tar xf harbor-offline-installer-v2.5.3.tgz -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  harbor  include  lib  lib64  libexec  sbin  share  src
[root@localhost local]# cd harbor/
[root@localhost harbor]# ls
common.sh  harbor.v2.5.3.tar.gz  harbor.yml.tmpl  install.sh  LICENSE  prepare

//修改主机名称
[root@localhost harbor]# hostnamectl set-hostname harbor.example.com
[root@localhost harbor]# bash

//修改配置文件
[root@harbor harbor]# ls
common.sh  harbor.v2.5.3.tar.gz  harbor.yml.tmpl  install.sh  LICENSE  prepare
[root@harbor harbor]# cp harbor.yml.tmpl harbor.yml
[root@harbor harbor]# ls
common.sh  harbor.v2.5.3.tar.gz  harbor.yml  harbor.yml.tmpl  install.sh  LICENSE  prepare
[root@harbor harbor]# vim harbor.yml

# Configuration file of Harbor
  
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: harbor.example.com	#修改主机名称

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80

# https related config
#https:									#将https相关的全部注释
  # https port for harbor, default is 443
  #port: 443
  # The path of cert and key files for nginx
  #certificate: /your/certificate/path
  #private_key: /your/private/key/path

# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: Harbor12345      #这里设置的是密码

# Harbor DB configuration
........
//安装harbor
[root@harbor harbor]# ./install.sh
安装过程......  #这个需要等待一会----Harbor has been installed and started successfully.----
[root@harbor harbor]# 

//设置开机自启
[root@harbor harbor]# vim /etc/rc.local 
......
# that this script will be executed during boot.

touch /var/lock/subsys/local

cd /usr/local/harbor										
docker-compose start
#添加这两行

[root@harbor harbor]# ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Dec  2  2020 /etc/rc.local -> rc.d/rc.local

[root@harbor harbor]# chmod +x /etc/rc.d/rc.local 
[root@harbor harbor]# ll /etc/rc.d/rc.local 
-rwxr-xr-x. 1 root root 525 Aug 11 19:34 /etc/rc.d/rc.local
#然后重启
[root@harbor ~]# reboot
[root@harbor ~]# docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED         STATUS                             PORTS                                   NAMES
d934dbfe6607   goharbor/nginx-photon:v2.5.3         "nginx -g 'daemon of…"   2 minutes ago   Up 8 seconds (health: starting)    0.0.0.0:80->8080/tcp, :::80->8080/tcp   nginx
1e61bdd87a11   goharbor/harbor-jobservice:v2.5.3    "/harbor/entrypoint.…"   2 minutes ago   Up 8 seconds (health: starting)                                            harbor-jobservice
6344d82c024d   goharbor/harbor-core:v2.5.3          "/harbor/entrypoint.…"   2 minutes ago   Up 10 seconds (health: starting)                                           harbor-core
b5eb05f42c51   goharbor/harbor-registryctl:v2.5.3   "/home/harbor/start.…"   2 minutes ago   Up 10 seconds (health: starting)                                           registryctl
cea7f19016ed   goharbor/harbor-portal:v2.5.3        "nginx -g 'daemon of…"   2 minutes ago   Up 9 seconds (health: starting)                                            harbor-portal
beaeb8c5a1a1   goharbor/harbor-db:v2.5.3            "/docker-entrypoint.…"   2 minutes ago   Up 9 seconds (health: starting)                                            harbor-db
97871e9cf034   goharbor/registry-photon:v2.5.3      "/home/harbor/entryp…"   2 minutes ago   Up 9 seconds (health: starting)                                            registry
c58efa3f8e79   goharbor/redis-photon:v2.5.3         "redis-server /etc/r…"   2 minutes ago   Up 9 seconds (health: starting)                                            redis
99c54d8f6865   goharbor/harbor-log:v2.5.3           "/bin/sh -c /usr/loc…"   2 minutes ago   Up 9 seconds (health: starting)    127.0.0.1:1514->10514/tcp               harbor-log
[root@harbor ~]# 

.......

访问测试,然后登录
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Harbor 是一个开源的云原生镜像仓库,支持 Docker 和 Kubernetes。搭建 Harbor 镜像仓库可以方便地管理和部署 Docker 镜像。 以下是 Harbor 镜像仓库搭建步骤: 1. 安装 DockerDocker Compose 首先需要在服务器上安装 DockerDocker Compose,可以参考 Docker 官方文档进行安装。 2. 下载并解压 Harbor 安装包 在 Harbor 的官网上下载最新版本的 Harbor 安装包,解压到服务器上的任意目录。 3. 配置 Harbor 进入 Harbor 安装包所在目录,编辑 `harbor.cfg` 文件,配置相关参数,例如: ``` hostname = example.com ui_url_protocol = https harbor_admin_password = StrongPassword ``` 这里的 `hostname` 是 Harbor 的访问地址,`ui_url_protocol` 是访问协议,`harbor_admin_password` 是管理员密码。 4. 启动 HarborHarbor 安装包所在目录下执行以下命令启动 Harbor: ``` docker-compose up -d ``` 这会启动 Harbor 的所有组件,并且在后台运行。 5. 配置 Docker 客户端 在需要使用 Harbor 镜像仓库的客户端机器上,编辑 Docker 配置文件 `/etc/docker/daemon.json`,加入以下内容: ``` { "insecure-registries": ["example.com"] } ``` 这里的 `example.com` 是 Harbor 的访问地址。 6. 登录 Harbor 在客户端机器上执行以下命令登录 Harbor: ``` docker login example.com ``` 这里的 `example.com` 是 Harbor 的访问地址。 7. 使用 Harbor 登录成功后,就可以使用 Harbor 镜像仓库了,例如: ``` docker pull example.com/library/nginx:latest docker push example.com/library/nginx:latest ``` 这里的 `library/nginx` 是一个示例镜像,可以替换成其他镜像。 以上是 Harbor 镜像仓库搭建步骤,希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值