行业知识
Docker学习之使用harbor搭建私有仓库(超详解析)
2026-11-29 00:40:43
来源:互联网转载
实验目的:
使���centos7,基于harbor构建私有仓库
实验步骤:
下载相关安装包和依赖:
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 wget //安装docker所需要的相关依赖[root@localhost ~]# wget -O /etc/yum.repos.d/docker-ce.repohttps://repo.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo //根据版本不同,下载repo文件[root@localhost ~]# yum install docker-ce //安装docker-ce[root@localhost ~]# yum list | grep ^docker- //查看是否有docker-compose,未发现相应版本[root@localhost ~]# wget -c https://github.com/docker/compose/releases/download/v2.24.6/docker-compose-linux-x86_64 //从github上下载docker-compose,如果github下载速度太慢,可以使用迅雷或网盘等相应下载工具进行下载关于harbor的下载:https://github.com/goharbor/harbor/releases //与docker-compose类似,在github上选择相应版本(本次实验所用版本为2.8.4版本)进行下载
对harbor安装时相关配置:
[root@localhost ~]# ls //查看docker-compose和harbor是否存在anaconda-ks.cfgdocker-compose-linux-x86_64harbor-offline-installer-v2.8.4.tgz[root@localhost ~]# mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose //先将docker-compose移动至//usr/local/bin/docker-compose路径下[root@localhost ~]# ll /usr/local/bin/docker-compose //查看docker-compose权限-rw-r--r--. 1 root root 61431093 3月 17 14:14 /usr/local/bin/docker-compose[root@localhost ~]# chmod +x /usr/local/bin/docker-compose //给docker-compose赋予相应权限[root@localhost ~]# docker-compose version //查看docker-compose版本信息Docker Compose version v2.24.6[root@localhost ~]# tar xf harbor-offline-installer-v2.8.4.tgz -C /usr/local/ //使用tar将harbor解压缩至/usr/local/路径下[root@localhost ~]# cd /usr/local/harbor/ //切换到该目录[root@localhost harbor]# ls //查看该路径下的文件信息common.sh harbor.yml.tmpl LICENSEharbor.v2.8.4.tar.gz install.sh prepare[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml //将harbor.yml.tmpl拷贝信息为harbor.yml[root@localhost harbor]# vim harbor.yml //进入harbor.yml修改配置文件hostname: reg.openlab.cn//更改hostname# http related confighttp: # port for http, default is 80. If https enabled, this port will redirect to https port port: 80 //http不做修改# 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 //对https的相关内容进行注释harbor_admin_password: 123456 //修改了登陆harbor时的密码[root@localhost harbor]# systemctl start docker //启动docker服务[root@localhost harbor]# ./install.sh //使用install.sh进行下载[Step 5]: starting Harbor ...[+] Running 9/10 ⠙ Network harbor_harbor Created 2.1s ✔ Container harbor-log Started 0.4s ✔ Container registryctl Started 1.0s ✔ Container harbor-portal Started 0.9s ✔ Container registry Started 0.8s ✔ Container redis Started 1.1s ✔ Container harbor-db Started 0.9s ✔ Container harbor-core Started 1.4s ✔ Container nginx Started 1.8s ✔ Container harbor-jobservice Started 1.8s ✔ ----Harbor has been installed and started successfully.----[root@localhost harbor]# docker-compose ps //查看状态信息NAME IMAGE COMMAND SERVICE CREATED STATUS PORTSharbor-core goharbor/harbor-core:v2.8.4 "/harbor/entrypoint.…" core About a minute ago Up About a minute (healthy) harbor-db goharbor/harbor-db:v2.8.4 "/docker-entrypoint.…" postgresql About a minute ago Up About a minute (healthy) harbor-jobservice goharbor/harbor-jobservice:v2.8.4 "/harbor/entrypoint.…" jobservice About a minute ago Up About a minute (healthy) harbor-log goharbor/harbor-log:v2.8.4 "/bin/sh -c /usr/loc…" log About a minute ago Up About a minute (healthy) 127.0.0.1:1514->10514/tcpharbor-portal goharbor/harbor-portal:v2.8.4 "nginx -g 'daemon of…" portal About a minute ago Up About a minute (healthy) nginx goharbor/nginx-photon:v2.8.4 "nginx -g 'daemon of…" proxy About a minute ago Up About a minute (healthy) 0.0.0.0:80->8080/tcp, :::80->8080/tcpredis goharbor/redis-photon:v2.8.4 "redis-server /etc/r…" redis About a minute ago Up About a minute (healthy) registry goharbor/registry-photon:v2.8.4 "/home/harbor/entryp…" registry About a minute ago Up About a minute (healthy) registryctl goharbor/harbor-registryctl:v2.8.4 "/home/harbor/start.…" registryctl About a minute ago Up About a minute (healthy)
使用虚拟机ip进行验证:
登陆后页面如下:
可以点击新建项目:
可以对用户进行管理(将新创建的用户以维护人员身份添加到项目组中):
尝试相关推送命令:
[root@localhost ~]# docker images //查看本地镜像信息REPOSITORY TAG IMAGE ID CREATED SIZEbusybox latest beae173ccac6 2 years ago 1.24MBmyubuntu 18.04 5a214d77f5d7 2 years ago 63.1MB[root@localhost ~]# vim /etc/docker/daemon.json //进入daemon.json进行添加{ "registry-mirrors": ["https://lpk5rspy.mirror.aliyuncs.com"], "insecure-registries":["reg.openlab.cn"] //添加行}[root@localhost ~]# vim /etc/hosts //进入/etc/hosts进行添加127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.27.146 reg.openlab.cn //添加行[root@localhost ~]# systemctl daemon-reload //重新加载本地daemon[root@localhost ~]# systemctl restart docker //重新启动docker[root@localhost ~]# docker login reg.openlab.cn //命令行模式登录reg.openlab.cnUsername: tomPassword: WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded[root@localhost ~]# docker tag busybox:latest reg.openlab.cn/openlab/busybox:v1 //在项目中标记镜像[root@localhost ~]# docker push reg.openlab.cn/openlab/busybox //推送镜像到当前项目The push refers to repository [reg.openlab.cn/openlab/busybox]01fd6df81c8e: Pushed v1: digest: sha256:62ffc2ed7554e4c6d360bce40bbcf196573dd27c4ce080641a2c59867e732dee size: 527 进入web界面进行查看
上一篇:连接华为电脑数位板教程
下一篇:手机云服务器怎么进入桌面?