BoyChai's Blog - 镜像仓库 https://blog.boychai.xyz/index.php/tag/%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93/ Harbor-容器镜像仓库(部署和简单使用) https://blog.boychai.xyz/index.php/archives/41/ 2022-10-08T05:31:47+00:00 Harbor概述Harbor是由VMware公司开源的容器镜像仓库。事实上,Harbor是在docker registry上进行企业级扩展,从而获得了更加广泛的应用。官网:https://goharbor.io/GitHub:https://github.com/goharbor/harbor部署先决条件服务器硬件配置最低要求:CPU2核、内存4G、硬盘40GB推荐:CPU4核、内存8G、硬盘160GB软件Docker CE 17.06版本+Docker Compose 1.18版本+Harbor安装方式在线安装:从Docker Hub下载Harbor相关镜像。离线安装:安装包包含部署的相关镜像,安装包很大。Harbor部署docker version:Docker version 20.10.18, build b40c2f6docker-compose version: Docker Compose version v2.11.2harbor version: v2.6.0本文采用离线安装的方式,harbor的下载地址:https://github.com/goharbor/harbor/releases下载好并上传至服务器中,安装具体流程如下[root@harbor ~]# tar xvf harbor-offline-installer-v2.6.0.tgz harbor/harbor.v2.6.0.tar.gz harbor/prepare harbor/LICENSE harbor/install.sh harbor/common.sh harbor/harbor.yml.tmpl [root@harbor ~]# cd harbor [root@harbor harbor]# cp harbor.yml.tmpl harbor.yml # 修改hostname字段(域名),注释https相关配置,修改harbor_admin_password字段(初始密码) [root@harbor harbor]# vim harbor.yml hostname: harbor.host.com harbor_admin_password: Harbor12345 # 初始化环境(导入镜像) [root@harbor harbor]# ./prepare # 安装 [root@harbor harbor]# ./install.sh访问服务器80端口即可,默认用户为admin,密码为harbor.yml里面的harbor_admin_password设定的值Harbor基本使用添加信任仓库如果harbor搭建禁用掉了https,那么就要做一下操作:编辑/etc/docker/daemon.json,添加以下配置{ "insecure-registries": ["192.16.1.3"], }后面是服务器的ip或者域名,保存重启,使用下面命令检查[root@harbor harbor]# docker info |grep -A1 Insecure Insecure Registries: 192.16.1.3注意:基本使用实在客户端用的,如果在服务端使用并且重启docker之后harbor的网页掉了则需要再次进入harbor目录使用docker-compose启动harbor上传镜像在上传镜像之前需要有上传镜像的权限,我们直接使用admin来上传镜像,使用下面命令来登录harbor[root@harbor harbor]# docker login 192.16.1.3 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上传镜像到对应仓库的时候需要修改tag,tag格式为“仓库域名或ip/镜像位置/镜像名称:版本号”例如hello-world这个镜像,上传到刚才搭建的镜像仓库方法如下[root@harbor harbor]# docker tag hello-world:latest 192.16.1.3/library/my-hello-world:v1.0 [root@harbor harbor]# docker push 192.16.1.3/library/my-hello-world:v1.0 The push refers to repository [192.16.1.3/library/my-hello-world] e07ee1baac5f: Pushed v1.0: digest: sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4 size: 525下载镜像下载镜像时只需要在pull的时候输好镜像全称即可,例如[root@harbor harbor]# docker pull 192.16.1.3/library/my-hello-world:v1.0 v1.0: Pulling from library/my-hello-world Digest: sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4 Status: Downloaded newer image for 192.16.1.3/library/my-hello-world:v1.0 192.16.1.3/library/my-hello-world:v1.0