Docker学习之使用harbor搭建私有仓库(超详解析)

实验目的:

使用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.repo
https://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.cfg
docker-compose-linux-x86_64
harbor-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  LICENSE
harbor.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 config
http:
  # 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                        PORTS
harbor-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/tcp
harbor-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/tcp
redis               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             SIZE
busybox             latest              beae173ccac6        2 years ago         1.24MB
myubuntu            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.localdomain6
192.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.cn
Username: tom
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@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界面进行查看
相关推荐
此生只爱蛋14 分钟前
【Linux】正/反向代理
linux·运维·服务器
qq_54702617921 分钟前
Linux 基础
linux·运维·arm开发
yuhaiqun198922 分钟前
Typora 技能进阶:从会写 Markdown 到玩转配置 + 插件高效学习笔记
经验分享·笔记·python·学习·学习方法·ai编程·markdown
zfj32127 分钟前
sshd除了远程shell外还有哪些功能
linux·ssh·sftp·shell
废春啊33 分钟前
前端工程化
运维·服务器·前端
我只会发热36 分钟前
Ubuntu 20.04.6 根目录扩容(图文详解)
linux·运维·ubuntu
爱潜水的小L1 小时前
自学嵌入式day34,ipc进程间通信
linux·运维·服务器
保持低旋律节奏1 小时前
linux——进程状态
android·linux·php
zhuzewennamoamtf1 小时前
Linux I2C设备驱动
linux·运维·服务器
TSAI1 小时前
Docker Swarm 集群部署 Eureka 服务注册中心:高可用微服务架构的基石
spring cloud·docker