赞
踩
无论是使用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是由VMWare在Docker Registry的基础之上进行了二次封装,加进去了很多额外程序,而且提供了一个非常漂亮的web界面。
Project Harbor是一个开源的可信云本地注册项目,用于存储、标记和扫描上下文。
Harbor扩展了开源Docker分发版,增加了用户通常需要的功能,如安全、身份和管理。
Harbor支持高级特性,如用户管理、访问控制、活动监视和实例之间的复制。
Feathers:
Harbor在物理机上部署是非常难的,而为了简化Harbor的应用,Harbor官方直接把Harbor做成了在容器中运行的应用,而且这个容器在Harbor中依赖类似redis、mysql、pgsql等很多存储系统,所以它需要编排很多容器协同起来工作,因此VMWare Harbor在部署和使用时,需要借助于Docker的单机编排工具(Docker compose)来实现。
Compose是一个用于定义和运行多容器Docker应用程序的工具。使用Compose,您可以使用一个YAML文件来配置应用程序的服务。然后,使用一个命令创建并启动配置中的所有服务。
安装插件的位置:Install Docker Compose CLI plugin | Docker Documentation
//把docker-ce.repo移到另一台虚拟机中, [root@client ~]# cd /etc/yum.repos.d/ [root@client yum.repos.d]# ls CentOS-Stream-AppStream.repo CentOS-Stream-BaseOS.repo CentOS-Stream-Debuginfo.repo CentOS-Stream-Extras.repo CentOS-Stream-HighAvailability.repo CentOS-Stream-Media.repo CentOS-Stream-PowerTools.repo CentOS-Stream-RealTime.repo docker-ce.repo [root@client yum.repos.d]# scp docker-ce.repo 192.168.205.147:/etc/yum.repos.d/ The authenticity of host '192.168.205.147 (192.168.205.147)' can't be established. ECDSA key fingerprint is SHA256:0dG+IOnYI1di/+qAlI8c9kIiEXd/uGz+Fp/Os/slSDQ. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.205.147' (ECDSA) to the list of known hosts. root@192.168.205.147's password: docker-ce.repo 100% 2261 2.0MB/s 00:00 //安装docker [root@harbor ~]# cd /etc/yum.repos.d/ [root@harbor yum.repos.d]# ls CentOS-Stream-AppStream.repo CentOS-Stream-BaseOS.repo CentOS-Stream-Debuginfo.repo CentOS-Stream-Extras.repo CentOS-Stream-HighAvailability.repo CentOS-Stream-Media.repo CentOS-Stream-PowerTools.repo CentOS-Stream-RealTime.repo docker-ce.repo [root@harbor yum.repos.d]# dnf -y install docker-ce Failed to set locale, defaulting to C.UTF-8 CentOS Stream 8 - AppStream 442 kB/s | 24 MB 00:56 CentOS Stream 8 - BaseOS 6.1 MB/s | 25 MB 00:04 CentOS Stream 8 - Extras 16 kB/s | 18 kB 00:01 Docker CE Stable - x86_64 19 kB/s | 26 kB 00:01 Dependencies resolved. ================================================================== Package Arch Version Repository Size ================================================================== Installing: docker-ce x86_64 3:20.10.17-3.el8 docker-ce-stable 22 M Upgrading: libsemanage x86_64 2.9-8.el8 baseos 168 k policycoreutils x86_64 2.9-19.el8 baseos 374 k //安装插件 [root@harbor yum.repos.d]# cd [root@harbor ~]# ls -a . .bash_logout .config .tcshrc .. .bash_profile .cshrc anaconda-ks.cfg .bash_history .bashrc .ssh [root@harbor ~]# DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} [root@harbor ~]# mkdir -p $DOCKER_CONFIG/cli-plugins [root@harbor ~]# ls anaconda-ks.cfg [root@harbor ~]# ls -a . .bash_logout .config .ssh .. .bash_profile .cshrc .tcshrc .bash_history .bashrc .docker anaconda-ks.cfg [root@harbor ~]# ls .docker/ cli-plugins [root@harbor ~]# 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 100 24.5M 100 24.5M 0 0 21776 0 0:19:44 0:19:44 --:--:-- 25806 [root@harbor ~]# cd .docker/ [root@harbor .docker]# ls cli-plugins [root@harbor .docker]# cd cli-plugins/ [root@harbor cli-plugins]# ls docker-compose [root@harbor cli-plugins]# systemctl enable --now docker Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service. //设置权限 [root@harbor cli-plugins]# chmod +x docker-compose [root@harbor cli-plugins]# ll total 25188 -rwxr-xr-x. 1 root root 25792512 Aug 11 18:53 docker-compose [root@harbor cli-plugins]# pwd /root/.docker/cli-plugins [root@harbor cli-plugins]# ls docker-compose [root@harbor cli-plugins]# ln -s /root/.docker/cli-plugins/docker-compose /usr/bin/ [root@harbor cli-plugins]# cd [root@harbor ~]# which docker-compose /usr/bin/docker-compose [root@harbor ~]# docker compose version Docker Compose version v2.7.0 //上传压缩包 [root@harbor ~]# ls anaconda-ks.cfg harbor-offline-installer-v2.5.3.tgz [root@harbor ~]# [root@harbor ~]# tar xf harbor-offline-installer-v2.5.3.tgz -C /usr/local/ [root@harbor ~]# cd /usr/local/ [root@harbor local]# ls bin games include lib64 sbin src etc harbor lib libexec share [root@harbor local]# cd harbor/ [root@harbor harbor]# ls LICENSE harbor.v2.5.3.tar.gz install.sh common.sh harbor.yml.tmpl prepare [root@harbor harbor]# cp harbor.yml.tmpl harbor.yml //修改配置文件 [root@harbor harbor]# vim harbor.yml hostname: harbor.example.com //修改为主机名 # 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@harbor harbor]# ls LICENSE harbor.v2.5.3.tar.gz harbor.yml.tmpl prepare common.sh harbor.yml install.sh [root@harbor harbor]# ./install.sh [Step 0]: checking if docker is installed ... Note: docker version: 20.10.17 [Step 1]: checking docker-compose is installed ... Note: docker-compose version: 2.7.0 ............................... [+] Running 10/10 ⠿ Network harbor_harbor C... 0.2s ⠿ Container harbor-log St... 0.6s ⠿ Container harbor-db Sta... 1.6s ⠿ Container registryctl S... 2.8s ⠿ Container redis Started 2.2s ⠿ Container harbor-portal Started 3.2s ⠿ Container registry Star... 3.1s ⠿ Container harbor-core S... 3.7s ⠿ Container nginx Started 4.9s ⠿ Container harbor-jobservice Started 4.8s ✔ ----Harbor has been installed and started successfully.---- [root@harbor harbor]# ss -antl 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 ~]# vim /etc/rc.local [root@harbor ~]# ll /etc/rc.local lrwxrwxrwx. 1 root root 13 Dec 2 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 19:14 /etc/rc.d/rc.local [root@harbor ~]# chmod +x /etc/rc.d/rc.local //重启虚拟机 [root@harbor ~]# reboot 连接断开 连接成功 Last login: Thu Aug 11 18:13:12 2022 from 192.168.205.1 [root@harbor ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eb49b41ed331 goharbor/nginx-photon:v2.5.3 "nginx -g 'daemon of…" 16 minutes ago Up 3 seconds (health: starting) 0.0.0.0:80->8080/tcp, :::80->8080/tcp nginx 1eeabbf507ee goharbor/harbor-jobservice:v2.5.3 "/harbor/entrypoint.…" 16 minutes ago Up 3 seconds (health: starting) harbor-jobservice 0bab1f1b7cac goharbor/harbor-core:v2.5.3 "/harbor/entrypoint.…" 16 minutes ago Up 4 seconds (health: starting) harbor-core 1a9a39c54601 goharbor/harbor-portal:v2.5.3 "nginx -g 'daemon of…" 16 minutes ago Up 7 seconds (health: starting) harbor-portal 105ffa682b26 goharbor/redis-photon:v2.5.3 "redis-server /etc/r…" 16 minutes ago Up 2 seconds (health: starting) redis 6a7359e96d3d goharbor/harbor-db:v2.5.3 "/docker-entrypoint.…" 16 minutes ago Up 3 seconds (health: starting) harbor-db 0c0610173a9e goharbor/harbor-registryctl:v2.5.3 "/home/harbor/start.…" 16 minutes ago Up 3 seconds (health: starting) registryctl 2d65807b259a goharbor/registry-photon:v2.5.3 "/home/harbor/entryp…" 16 minutes ago Up 6 seconds (health: starting) registry def9e9b8ed9d goharbor/harbor-log:v2.5.3 "/bin/sh -c /usr/loc…" 16 minutes ago Up 5 seconds (health: starting) 127.0.0.1:1514->10514/tcp harbor-log
[root@client ~]# vim /etc/hosts
192.168.205.147 harbor.example.com
[root@client ~]# ping harbor.example.com
PING harbor.example.com (192.168.205.147) 56(84) bytes of data.
64 bytes from harbor.example.com (192.168.205.147): icmp_seq=1 ttl=64 time=0.404 ms
64 bytes from harbor.example.com (192.168.205.147): icmp_seq=2 ttl=64 time=0.226 ms
^C
--- harbor.example.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1033ms
rtt min/avg/max/mdev = 0.226/0.315/0.404/0.089 ms
[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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。