Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。作为一个企业级私有Registry服务器,Harbor提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率。Harbor支持安装在多个Registry节点的镜像资源复制,镜像全部保存在私有Registry中, 确保数据和知识产权在公司内部网络中管控。另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。
基于角色的访问控制 :用户与Docker镜像仓库通过“项目”进行组织管理,一个用户可以对多个镜像仓库在同一命名空间(project)里有不同的权限。
镜像复制 :镜像可以在多个Registry实例中复制(同步)。尤其适合于负载均衡,高可用,混合云和多云的场景。
图形化用户界面 :用户可以通过浏览器来浏览,检索当前Docker镜像仓库,管理项目和命名空间。
AD/LDAP 支持 :Harbor可以集成企业内部已有的AD/LDAP,用于鉴权认证管理。
审计管理 :所有针对镜像仓库的操作都可以被记录追溯,用于审计管理。
国际化 :已拥有英文、中文、德文、日文和俄文的本地化版本。更多的语言将会添加进来。
RESTful API :RESTful API 提供给管理员对于Harbor更多的操控, 使得与其它管理软件集成变得更容易。
部署简单 :提供在线和离线两种安装工具, 也可以安装到vSphere平台(OVA方式)虚拟设备。
Harbor在架构上主要由6个组件构成:
各个组件之间的关系如下图所示:
在这里插入图片描述
CentOS 7.5
Docker 19.03.8
Docker Engine 19.03.8
Docker-compose 1.25.4
Harbor 1.5.0
低版本,速度快:http://harbor.orientsoft.cn/ 版本全,速度慢:https://github.com/goharbor/harbor/releases
1.下载解压
[root@localhost harbor]# wget http://harbor.orientsoft.cn/harbor-v1.5.0/harbor-offline-installer-v1.5.0.tgz
[root@localhost harbor]# ls
harbor-offline-installer-v1.5.0.tgz
[root@localhost harbor]# tar -xvf harbor-offline-installer-v1.5.0.tgz
[root@localhost harbor]# cd harbor
[root@localhost harbor]# ls
common docker-compose.notary.yml ha harbor.v1.5.0.tar.gz LICENSE prepare
docker-compose.clair.yml docker-compose.yml harbor.cfg install.sh NOTICE
2.修改配置文件
[root@localhost harbor]# vim harbor.cfg
...
#DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname = 192.168.2.195
//设置访问地址,可以是ip、主机名,不可以设置为127.0.0.1或localhost
ui_url_protocol = http //不使用https就改为http
[root@localhost harbor]# ./prepare //执行官方自带脚本更新配置文件
3.开始安装
修改完配置文件后,在当前目录执行./install.sh,Harbor服务就会根据当前目录下的docker-compose.yml开始下载依赖的镜像,检测并按照顺序依次启动各服务。
[root@localhost harbor]# ./install.sh
[Step 0]: checking installation environment ...
Note: docker version: 19.03.8
Note: docker-compose version: 1.25.4
[Step 1]: loading Harbor images ...
52ef9064d2e4: Loading layer [==================================================>] 135.9MB/135.9MB
...
...
[Step 2]: preparing environment ...
Generated and saved secret to file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/log/logrotate.conf
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.
[Step 3]: checking existing instance of Harbor ...
[Step 4]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating registry ... done
Creating redis ... done
Creating harbor-db ... done
Creating harbor-adminserver ... done
Creating harbor-ui ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://192.168.2.195.
For more details, please visit https://github.com/vmware/harbor .
查看生成的容器:
[root@localhost harbor]# docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------------------------
harbor-adminserver /harbor/start.sh Up (healthy)
harbor-db /usr/local/bin/docker-entr ... Up (healthy) 3306/tcp
harbor-jobservice /harbor/start.sh Up
harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp
harbor-ui /harbor/start.sh Up (healthy)
nginx nginx -g daemon off; Up (healthy) 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp,
0.0.0.0:80->80/tcp
redis docker-entrypoint.sh redis ... Up 6379/tcp
registry /entrypoint.sh serve /etc/ ... Up (healthy) 5000/tcp
说明:
这几个容器通过Docker link的形式连接在一起,在容器之间通过容器名字互相访问。对终端用户而言,只需要暴露proxy (即Nginx)的服务端口。
docker-compose up -d (相当于 build + start ):构建(容器)并启动(容器)整个project的所有service
docker-compose down -v(相当于 stop + rm ):停止并移除整个project的所有services
docker-compose start [serviceName]:启动已存在但停止的所有service
docker-compose stop [serviceName]:停止运行的service
docker-compose restart [serviceName]: 重启服务
docker-compose images:列出所用的镜像
docker-compose ps:查看正在运行的镜像
docker-compose down -v:停止并移除整个project的所有services
[root@localhost harbor]# docker-compose down -v
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-ui ... done
Stopping harbor-adminserver ... done
Stopping redis ... done
Stopping harbor-db ... done
Stopping registry ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-ui ... done
Removing harbor-adminserver ... done
Removing redis ... done
Removing harbor-db ... done
Removing registry ... done
Removing harbor-log ... done
Removing network harbor_harbor
docker-compose up -d :构建(容器)并启动(容器)整个project的所有service
[root@localhost harbor]# docker-compose up -d
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-adminserver ... done
Creating registry ... done
Creating harbor-db ... done
Creating redis ... done
Creating harbor-ui ... done
Creating harbor-jobservice ... done
Creating nginx ... done
执行Harbor 启动 / 停止、docker-compose ps等命令都必须在Harbor安装目录下执行才可以,否则会报错。
[root@localhost ~]# docker-compose ps
ERROR:
Can't find a suitable configuration file in this directory or any
parent. Are you in the right directory?
Supported filenames: docker-compose.yml, docker-compose.yaml
如果端口占用,我们需要修改Harbor安装目录下的docker-compose.yml文件,做对应服务的端口映射。(端口变化后修改配置文件带上端口)
[root@localhost harbor]# vim docker-compose.yml
...
proxy:
image: vmware/nginx-photon:v1.5.0
container_name: nginx
restart: always
volumes:
- ./common/config/nginx:/etc/nginx:z
networks:
- harbor
ports:
- 80:80 //修改此处为新端口,如:59:80
- 443:443
- 4443:4443
depends_on:
- mysql
- registry
- ui
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "proxy"
networks:
harbor:
external: false
启动完成后,我们访问刚才设置的hostname即:http://192.168.2.195,默认是80端口。
在这里插入图片描述 输入用户名:admin,默认密码:Harbor12345 登录系统。
在这里插入图片描述 管理员系统各个模块如下:
注意:
非系统管理员用户登录,只能看到有权限的项目和日志,其他模块不可见。
新建私有项目
在这里插入图片描述 上传(push)镜像
[root@localhost harbor]# docker tag nginx:latest 192.168.2.195/test/nginx:test
[root@localhost harbor]# docker push 192.168.2.195/test/nginx:test
[root@localhost harbor]# docker tag gatwayjar:latest 192.168.2.195/test/gatewayjar:test
[root@localhost harbor]# docker push 192.168.2.195/test/gatewayjar:test
The push refers to repository [192.168.2.195/test/gatewayjar]
7fa55cc3a370: Pushed
6d9807a29efe: Pushed
a52fcbff5465: Pushing [========================> ] 59.56MB/121.6MB
767f936afb51: Pushed
下载(pull)镜像
[root@localhost harbor]# docker pull 192.168.2.195/test/gatewayjar:test
test: Pulling from test/gatewayjar
169185f82c45: Already exists
4346af5b5a4f: Already exists
4094eab2320e: Already exists
c63e245a220a: Extracting [============> ] 11.3MB/46.36MB
在这里插入图片描述
Docker login Harbor报错解决:https://blog.csdn.net/qq_44895681/article/details/105573702