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界面。

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官方文档

Harbor部署

Harbor官方文档

[root@node02 ~]# yum -y install docker-compose   //先安装epel源   
[root@node02 ~]# cd /usr/src/
[root@node02 src]# wget https://github.com/goharbor/harbor/releases/download/v1.10.2/harbor-online-installer-v1.10.2.tgz

[root@node02 src]# ls
debug  harbor-online-installer-v1.10.2.tgz  kernels
[root@node02 src]# tar xf harbor-online-installer-v1.10.2.tgz -C /usr/local/
[root@node02 src]# ls /usr/local/
bin  etc  games  harbor  include  lib  lib64  libexec  sbin  share  src
[root@node02 src]# cd /usr/local/harbor/
[root@node02 harbor]# ls
common.sh   harbor.yml  install.sh  LICENSE  prepare

[root@node02 harbor]# vim harbor.yml
...
hostname: 192.168.73.131   //本机IP
...


[root@node02 harbor]# ./install.sh
[root@node02 harbor]# ss -antl
State       Recv-Q Send-Q                   Local Address:Port                                  Peer Address:Port              
LISTEN      0      128                          127.0.0.1:1514                                             *:*                  
LISTEN      0      128                                  *:22                                               *:*                  
LISTEN      0      128                               [::]:80                                            [::]:*                  
LISTEN      0      128                               [::]:22     

harbor的使用和管理

使用IP登录管理Harbor:
管理员密码默认为Harbor12345
Harbor_第1张图片
创建一个项目
Harbor_第2张图片
Harbor_第3张图片
上传镜像需要先登陆

[root@localhost ~]# cat /etc/docker/daemon.json 
{
  "insecure-registries": ["192.168.73.131"],
  "registry-mirrors": ["https://ix8u598x.mirror.aliyuncs.com"]
}
[root@localhost ~]# docker login 192.168.73.131
Authenticating with existing credentials...
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 ~]# docker images 
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
busybox                       latest              83aa35aa1c79        6 weeks ago         1.22MB
nginx                         latest              6678c7c2e56c        6 weeks ago         127MB
centos                        latest              470671670cac        3 months ago        237MB
centos                        7.4.1708            9f266d35e02c        13 months ago       197MB
[root@localhost ~]# docker tag nginx:latest 192.168.73.131/webapp/nginx:v0.1
[root@localhost ~]# docker images 
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
busybox                          latest              83aa35aa1c79        6 weeks ago         1.22MB
192.168.73.131/webapp/nginx      v0.1                6678c7c2e56c        6 weeks ago         127MB
nginx                            latest              6678c7c2e56c        6 weeks ago         127MB
centos                           latest              470671670cac        3 months ago        237MB
centos                           7.4.1708            9f266d35e02c        13 months ago       197MB

[root@localhost ~]# docker push 192.168.73.131/webapp/nginx:v0.1
The push refers to repository [192.168.73.131/webapp/nginx]
55a77731ed26: Pushed 
71f2244bc14d: Pushed 
f2cb0ecef392: Pushed 
latest: digest: sha256:3936fb3946790d711a68c58be93628e43cbca72439079e16d154b5db216b58da size: 948

Harbor_第4张图片
下拉镜像

[root@localhost ~]# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              83aa35aa1c79        6 weeks ago         1.22MB
nginx               latest              6678c7c2e56c        6 weeks ago         127MB
centos              latest              470671670cac        3 months ago        237MB
centos              7.4.1708            9f266d35e02c        13 months ago       197MB
[root@localhost ~]# docker pull 192.168.73.131/webapp/nginx:v0.1
v0.1: Pulling from webapp/nginx
Digest: sha256:3936fb3946790d711a68c58be93628e43cbca72439079e16d154b5db216b58da
Status: Downloaded newer image for 192.168.73.131/webapp/nginx:v0.1
192.168.73.131/webapp/nginx:v0.1
[root@localhost ~]# docker images 
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
busybox                       latest              83aa35aa1c79        6 weeks ago         1.22MB
192.168.73.131/webapp/nginx   v0.1                6678c7c2e56c        6 weeks ago         127MB
nginx                         latest              6678c7c2e56c        6 weeks ago         127MB
centos                        latest              470671670cac        3 months ago        237MB
centos                        7.4.1708            9f266d35e02c        13 months ago       197MB

你可能感兴趣的:(Harbor)