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 是一个开源的可信云原生注册表项目,用于存储、签名和扫描上下文。
Harbor 通过添加用户通常需要的功能(如安全性、身份和管理)来扩展开源 Docker 分发版。
Harbor 支持高级功能,例如用户管理、访问控制、活动监控和实例间复制。
Harbor的功能
Feathers:
- 多租户内容签名和验证
- 安全性和漏洞分析
- 审核日志记录
- 身份集成和基于角色的访问控制
- 实例之间的映像复制
- 可扩展的 API 和图形用户界面
- 国际化(现为英文和中文)
Docker compose
Harbor在物理机上部署是非常难的,而为了简化Harbor的应用,Harbor官方直接把Harbor做成了在容器中运行的应用,而且这个容器在Harbor中依赖类似redis、mysql、pgsql等很多存储系统,所以它需要编排很多容器协同起来工作,因此VMWare Harbor在部署和使用时,需要借助于Docker的单机编排工具(Docker compose)来实现。
Compose 是用于定义和运行多容器 Docker 应用程序的工具。使用 Compose,您可以使用 YAML 文件来配置应用程序的服务。然后,使用单个命令,从配置中创建并启动所有服务。
Harbor部署
[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 cli-plugins]# ls
docker-compose
[root@localhost cli-plugins]# chmod +x docker-compose
[root@localhost cli-plugins]# ls
docker-compose
[root@localhost ~]# docker compose version
Docker Compose version v2.7.0
[root@localhost ~]# ls
anaconda-ks.cfg
apr-1.7.0
apr-1.7.0.tar.gz
apr-util-1.6.1
apr-util-1.6.1.tar.gz
data
harbor-offline-installer-v2.5.3.tgz
html5大气医院网站源码.zip
htmlbao1
httpd-2.4.54
httpd-2.4.54.tar.gz
mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
php-7.4.30
php-7.4.30.tar.xz
phpMyAdmin-5.2.0-all-languages.zip
[root@localhost ~]# tar xf harbor-offline-installer-v2.5.3.tgz -C /usr/local/
[root@localhost ~]# ls /usr/local/
apache apr-util etc harbor lib libexec php7 share
apr bin games include lib64 mysql sbin src
[root@localhost ~]# cd /usr/local/harbor/
[root@localhost harbor]# ls
common.sh harbor.yml.tmpl LICENSE
harbor.v2.5.3.tar.gz install.sh prepare
[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml
[root@localhost harbor]# vim harbor.yml
accessed by external clients.
hostname: master.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 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
[root@localhost harbor]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost harbor]# ./install.sh
[root@localhost harbor]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 127.0.0.1:1514 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
登录后的界面
Harbor应用
准备一台客户机
在客户端使用的时候如果不是用的https则必须要在客户端的/etc/docker/daemon.json配置文件中配置insecure-registries参数
[root@slave1 ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://sdj8kwlf.mirror.aliyuncs.com"],
"insecure-registries": ["master.example.com"]
}
//添加服务器的域名映射
[root@slave1 ~]# vim /etc/hosts
192.168.58.130 master.example.com
[root@slave1 ~]# systemctl restart docker
[root@slave1 ~]# docker login master.example.com
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@slave1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chenlang123/httpd v0.1 0a876bd309f1 4 days ago 744MB
[root@slave1 ~]# docker tag chenlang123/httpd:v0.1 master.example.com/library/httpd:v0.01
[root@slave1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
master.example.com/library/httpd v0.01 0a876bd309f1 4 days ago 744MB
chenlang123/httpd v0.1 0a876bd309f1 4 days ago 744MB
//上传镜像
[root@slave1 ~]# docker push master.example.com/library/httpd:v0.01
The push refers to repository [master.example.com/library/httpd]
12da7c3b1809: Pushed
74ddd0ec08fa: Pushed
v0.01: digest: sha256:66462b764cd54659d99eae5c43000cab9b73d267ce275ba049d11877e38d0ab7 size: 742