Loading... # Harbor介绍 Harbor 是为企业用户设计的开源镜像仓库项目,包括了权限管理(RBAC)、LDAP、审计、安全漏洞扫描、镜像验真、管理界面、自我注册、HA等企业必需的功能,同时针对中国用户的特点,设计镜像复制和中文支持等功能。 官网:https://goharbor.io/ # Harbor安装部署 ```bash # 1.harbor安装的环境要求 # 安装Harbor必须有docker环境和docker-compose环境 yum install -y docker-ce yum install -y docker-compose # 2.解压harbor安装包 [root@docker ~]# wget https://github.com/goharbor/harbor/releases/download/v2.10.0/harbor-offline-installer-v2.10.0.tgz [root@docker ~]# tar xf harbor-offline-installer-v2.10.0.tgz [root@docker ~]cd harbor [root@docker ~/harbor]# ll total 605144 -rw-r--r-- 1 root root 619632806 Sep 4 2019 harbor.v1.9.0.tar.gz -rw-r--r-- 1 root root 5805 Sep 4 2019 harbor.yml.tmpl -rwxr-xr-x 1 root root 5088 Sep 4 2019 install.sh -rw-r--r-- 1 root root 11347 Sep 4 2019 LICENSE -rwxr-xr-x 1 root root 1748 Sep 4 2019 prepare # 3.复制配置模版并修改harbor配置 [root@docker ~/harbor]# cp -a harbor.yml.tmpl harbor.yml [root@docker ~/harbor]# vim harbor.yml hostname: hub.if010.com http: port: 80 https: port: 443 certificate: /root/harbor/cert/hub.if010.com.pem private_key: /root/harbor/cert/hub.if010.com.key harbor_admin_password: Harbor12345 # 4.执行安装脚本 [root@docker ~/harbor]# sh install.sh [Step 1]: loading Harbor images ... Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? # 5.启动docker [root@docker ~/harbor]# systemctl start docker [root@docker ~/harbor]# sh install.sh [Step 0]: checking installation environment ... Note: docker version: 24.0.7 Note: docker-compose version: 1.18.0 [Step 1]: loading Harbor images ... ... ... [Step 2]: preparing environment ... ... ... Creating redis ... done Creating harbor-core ... done Creating network "harbor_harbor" with the default driver Creating nginx ... done Creating harbor-db ... Creating registryctl ... Creating harbor-portal ... Creating redis ... Creating registry ... Creating harbor-core ... Creating nginx ... Creating harbor-jobservice ... ✔ ----Harbor has been installed and started successfully.---- Now you should be able to visit the admin portal at http://10.0.0.200. For more details, please visit https://github.com/goharbor/harbor . ``` 浏览器访问 `https://hub.if010.com` 默认用户名:admin 密码:Harbor12345  使用 `docker ps -a` 和 `docker images` 命令可以看到正在运行的容器 和 拉取到本地的镜像  # Harbor的使用 ## harbor新建项目 新建一个if010项目,在里面可以看到相关推送镜像的命令。  ## harbor上传镜像 将本地镜像上传至harbor的if010项目仓库中 ```bash # 1.修改镜像名称 # 查看镜像 [root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest e4720093a3c1 9 days ago 187MB # 给镜像改名(会生成一个新的镜像,与原镜像同一个ID) [root@docker ~]# docker tag nginx:latest hub.if010.com/if010/nginx:latest [root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest e4720093a3c1 9 days ago 187MB hub.if010.com/if010/nginx latest e4720093a3c1 9 days ago 187MB ### 命名规则 ### # 照着上面截图命名即可: # harbor服务器地址/项目名称/镜像名称:标签 # hub.if010.com/if010/nginx:latest # 2.修改docker配置文件,信任harbor仓库地址 # 如果证书是真实有效的话可以不进行该项配置 [root@docker /etc/docker]# vim daemon.json { "bip": "192.168.10.1/24", "registry-mirrors": ["https://pgz00k39.mirror.aliyuncs.com"], "insecure-registries": ["https://hub.if010.com"] } [root@docker01 ~]# systemctl restart docker # 3.登录harbor [root@docker ~]# docker login hub.if010.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 # 4.推送镜像 [root@docker ~]# docker push hub.if010.com/if010/nginx:latest Using default tag: latest The push refers to repository [hub.if010.com/if010/nginx:latest] 61a7fb4dabcd: Pushed bcc6856722b7: Pushed 188d128a188c: Pushed 7d52a4114c36: Pushed 3137f8f0c641: Pushed 84619992a45b: Pushed ceb365432eec: Pushed latest: digest: sha256:678226242061e7dd8c007c32a060b7695318f4571096cbeff81f84e50787f581 size: 1778 ``` 刷新查看:  # Harbor镜像Docker Hub 在仓库管理中添加Docker Hub目标  新建public公共项目,镜像代理选择刚刚添加的 DockerHub 目标  在客户端使用命令拉取DockerHub上的公共镜像 ```bash [root@docker ~]# docker pull hub.if010.com/public/nginx Using default tag: latest latest: Pulling from public/nginx e1caac4eb9d2: Pull complete 88f6f236f401: Pull complete c3ea3344e711: Pull complete cc1bb4345a3a: Pull complete da8fa4352481: Pull complete c7f80e9cdab2: Pull complete 18a869624cb6: Pull complete Digest: sha256:c26ae7472d624ba1fafd296e73cecc4f93f853088e6a9c13c0d52f6ca5865107 Status: Downloaded newer image for hub.if010.com/public/nginx:latest hub.if010.com/public/nginx:latest ``` 项目中查询镜像情况  最后修改:2024 年 02 月 24 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 -