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是一个开源的可信云本地注册项目,用于存储、标记和扫描上下文。
Harbor扩展了开源Docker分发版,增加了用户通常需要的功能,如安全、身份和管理。
Harbor支持高级特性,如用户管理、访问控制、活动监视和实例之间的复制。
Harbor的功能
Feathers:
多租户内容签名和验证
安全性和脆弱性分析
审计日志记录
身份集成和基于角色的访问控制
实例间的镜像复制
可扩展的API和图形用户界面
国际化(currently English and Chinese)
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
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 24.5M 100 24.5M 0 0 22452 0 0:19:08 0:19:08 --:--:-- 29789
[root@localhost ~]# ls .docker/
cli-plugins
[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 21:58 docker-compose
[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
上传解压配置harbor
[root@localhost ~]# ls //下载harbor包
anaconda-ks.cfg harbor-offline-installer-v2.5.3.tgz
[root@localhost ~]# tar xf harbor-offline-installer-v2.5.3.tgz -C /usr/local/
[root@localhost ~]# ls /usr/local/ //解压至/usr/local/目录下
bin etc games harbor include lib lib64 libexec sbin share src
[root@localhost ~]# cd /usr/local/harbor/
[root@localhost harbor]# ls
LICENSE common.sh harbor.v2.5.3.tar.gz harbor.yml.tmpl install.sh prepare
[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml
[root@localhost harbor]# hostnamectl set-hostname harbor.example.com
[root@localhost harbor]# bash //修改主机名
[root@harbor harbor]# vim harbor.yml
hostname: harbor.example.com //指定主机名
#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
[root@harbor harbor]# ls
LICENSE common.sh harbor.v2.5.3.tar.gz harbor.yml harbor.yml.tmpl install.sh prepare
[root@harbor harbor]# ./install.sh //执行脚本
⠿ Container redis Started 1.6s
⠿ Container harbor-core Started 2.2s
⠿ Container nginx Started 2.9s
⠿ Container harbor-jobservice Started 2.8s
✔ ----Harbor has been installed and started successfully.----
[root@harbor harbor]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
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 [::]:*
设置开机自启
[root@harbor ~]# vim /etc/rc.local //修改配置文件
#!/bin/bash
cd /usr/local/harbor
docker-compose start
[root@harbor ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Dec 1 2020 /etc/rc.local -> rc.d/rc.local
[root@harbor ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 516 Aug 11 22:31 /etc/rc.d/rc.local
[root@harbor ~]# chmod +x /etc/rc.d/rc.local //修改执行权限
[root@harbor ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 516 Aug 11 22:31 /etc/rc.d/rc.local
[root@harbor ~]# reboot //重启验证
[root@harbor ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
743a2d0abfe3 goharbor/harbor-jobservice:v2.5.3 "/harbor/entrypoint.…" 10 minutes ago Up 35 seconds (healthy) harbor-jobservice
9c9abef9e080 goharbor/nginx-photon:v2.5.3 "nginx -g 'daemon of…" 10 minutes ago Up 35 seconds (healthy) 0.0.0.0:80->8080/tcp, :::80->8080/tcp nginx
ce0a2105acb8 goharbor/harbor-core:v2.5.3 "/harbor/entrypoint.…" 10 minutes ago Up 36 seconds (healthy) harbor-core
de63f6497ee0 goharbor/redis-photon:v2.5.3 "redis-server /etc/r…" 10 minutes ago Up 36 seconds (healthy) redis
ec141b04c689 goharbor/harbor-db:v2.5.3 "/docker-entrypoint.…" 10 minutes ago Up 36 seconds (healthy) harbor-db
e84da2c09e1a goharbor/harbor-registryctl:v2.5.3 "/home/harbor/start.…" 10 minutes ago Up 36 seconds (healthy) registryctl
4c29d3eab6c4 goharbor/harbor-portal:v2.5.3 "nginx -g 'daemon of…" 10 minutes ago Up 36 seconds (healthy) harbor-portal
d3a04e7bdeeb goharbor/registry-photon:v2.5.3 "/home/harbor/entryp…" 10 minutes ago Up 37 seconds (healthy) registry
663c82b34b0f goharbor/harbor-log:v2.5.3 "/bin/sh -c /usr/loc…" 10 minutes ago Up 37 seconds (healthy) 127.0.0.1:1514->10514/tcp harbor-log
[root@harbor ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
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 [::]:*
添加映射关系
[root@client ~]# vim /etc/hosts
192.168.78.20 harbor.example.com
[root@client ~]# ping harbor.example.com
PING harbor.example.com (192.168.78.20) 56(84) bytes of data.
64 bytes from harbor.example.com (192.168.78.20): icmp_seq=1 ttl=64 time=0.062 ms
64 bytes from harbor.example.com (192.168.78.20): icmp_seq=2 ttl=64 time=0.058 ms
64 bytes from harbor.example.com (192.168.78.20): icmp_seq=3 ttl=64 time=0.064 ms
^C
--- harbor.example.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2077ms
rtt min/avg/max/mdev = 0.058/0.061/0.064/0.006 ms
登录harbor
[root@client ~]# vim /etc/docker/daemon.json
"insecure-registries": ["harbor.example.com"]
[root@client ~]# systemctl restart docker
[root@client ~]# docker login harbor.example.com
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
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
1919756426/httpd v0.1 e14b17a19b43 2 days ago 778MB
web/httpd v0.1 d950d0ef139d 4 days ago 778MB
busybox latest beae173ccac6 7 months ago 1.24MB
httpd latest dabbfbe0c57b 7 months ago 144MB
centos latest 5d0da3dc9764 11 months ago 231MB
[root@client ~]# docker tag web/httpd:v0.1 harbor.example.com/library/runtime:v0.2
[root@client ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
1919756426/httpd v0.1 e14b17a19b43 2 days ago 778MB
web/httpd v0.1 d950d0ef139d 4 days ago 778MB
harbor.example.com/library/runtime v0.2 d950d0ef139d 4 days ago 778MB
busybox latest beae173ccac6 7 months ago 1.24MB
httpd latest dabbfbe0c57b 7 months ago 144MB
centos latest 5d0da3dc9764 11 months ago 231MB
[root@client ~]# docker push harbor.example.com/library/runtime:v0.2
The push refers to repository [harbor.example.com/library/runtime]
b35a2137df69: Pushed
74ddd0ec08fa: Pushed
v0.2: digest: sha256:15c503b937c4266e2cb52c2903590d11259a052d177c97f6108db98b31f1815d size: 742