harbor搭建docker私有仓库

1. harbor

​ harbor 是一个企业级docker 镜像仓库

​ registry 是docker的私有仓库

​ 安全性比较好

​ 纯命令行操作,没有图形化界面

​ 仓库间镜像同步

​ 由于 registry 私有仓库确定太多,使用 harbor 进行替代

2. harbor 组件

在这里插入图片描述

1) proxy: 代理,主要实现对请求的识别和分发,内置的Nginx

​ 判断请求内容,根据请求内容,将求情转发至指定的组件服务

扫描二维码关注公众号,回复: 9572305 查看本文章

​ 2) registry: 主要实现啊对 docker pull /docker push 命令的响应

​ 3) log collector: 收集日志

​ 4) core service: 核心服务器

​ ui 提供Web界面

​ token 验证,用于验证访问的用户

​ webhook 命令行界面

​ 5) database 存储数据的地方

​ 6) Job service 负责镜像复制工作,它和registry通信,从一个registry pull镜像然后 push到另一个 registry

3. 安装harbor

​ 启动 harbor 需要 docker 的支持,所以先安装docker

实验环境:

​ docker-client: 192.168.116.103

​ 所需软件: docker-ce

​ docker-harbor: 192.168.116.103

​ 所需软件: docker-ce

harbor-offline-installer-v1.6.2.tgz

docker-compose

1) 安装docker(docker-client、docker-harbor)

  • 安装 yum-config-manager 工具
[root@localhost ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
  • 指定国内 docker
[root@localhost ~]# yum-config-manager --add-repo=http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • 新建缓存
[root@localhost ~]# yum makecache fast
  • yum安装 docker-ce
[root@localhost ~]#  yum -y install  docker-ce
  • 如出现以下报错

    错误:软件包:3:docker-ce-19.03.6-3.el7.x86_64 (docker-ce-stable)
    需要:container-selinux >= 2:2.74
    错误:软件包:containerd.io-1.2.10-3.2.el7.x86_64 (docker-ce-stable)
    需要:container-selinux >= 2:2.74
    您可以尝试添加 --skip-broken 选项来解决该问题

  • 解决方案

wget http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.107-1.el7_6.noarch.rpm

​ - 安装:

rpm -ivh container-selinux-2.107-1.el7_6.noarch.rpm --nodeps --force
  • 再次安装 docker-ce
[root@localhost ~]#  yum -y install  docker-ce
  • 启动docker
[root@localhost ~]# systemctl start docker
  • 创建镜像
[root@localhost ~]# docker pull hello-world
  • 镜像加速

    可参考:https://blog.csdn.net/weixin_43557605/article/details/104447317

    curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
    
    [root@localhost ~]# systemctl daemon-reload
    [root@localhost ~]# systemctl restart docker
    
    

2) 安装 harbor

[root@localhost ~]# tar -zxf harbor-offline-installer-v1.6.2.tgz -C /usr/local
[root@localhost ~]# mv docker-compose /usr/local/bin/
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose 
[root@localhost ~]# cd /usr/local/harbor/
  • 指定 harbor的地址
[root@localhost harbor]# vim harbor.cfg 

	hostname = 192.168.116.104
  • 执行安装脚本

    
    [root@localhost harbor]# ./install.sh # 以下 为 成功启动
    
    ​	✔ ----Harbor has been installed and started successfully.----	
    

关于 harbor的启动

  • 以下操作在 harbor 目录中执行

​ 安装完 harbor 之后,会自动进行第一次的启动

	docker-compose start

harbor的关闭

	docker-compose stop

harbor的重启

	建议先关闭重启

​	docker-compose start

​	docker-compose stop
  • 登入 harbor ui界面

harbor 默认的账户密码

​ 账户: admin

​ 密码: Harbor12345

http://192.168.116.104/harbor/projects

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3)上传 镜像(docker-client)

  • 查看所有镜像
[root@localhost harbor]# docker images
  • 打标签
    • 上传镜像需要,先打标签,hello-world:latest 路径
      • 192.168.116.104/harbor/hello-world 上传的镜像
[root@localhost ~]# docker tag hello-world:latest 192.168.116.104/harbor/hello-world

  • 登录 harbor
[root@localhost ~]# docker login -u admin -p Harbor12345 192.168.116.104

WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://192.168.116.104/v2/: dial tcp 192.168.116.104:443: connect: connection refused

​ # 报错,因为当前docker 不认识 harbor,需要添加至 配合文件

解决方法:

[root@localhost ~]# vim /usr/lib/systemd/system/docker.service 

ExecStart=/usr/bin/dockerd --insecure-registry 192.168.116.104		# 14 修改,指定 harbor
  • 重启 docker 服务
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
  • 再次登录
[root@localhost ~]# docker login -u admin -p Harbor12345 192.168.116.104

WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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
  • 上传镜像至 harbor/hello-world
[root@localhost ~]# docker push 192.168.116.104/harbor/hello-world
The push refers to repository [192.168.116.104/harbor/hello-world]
af0b15c8625b: Pushed 
latest: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524


4. harbor 实例之间镜像传输

​ 实现环境:

​ host 1: 192.168.116.103

​ harbor1: 192.168.116.104

​ harbor2: 192.168.116.105

1) 在 harbor 1 中创建项目 harbor

在这里插入图片描述

2) 创建复制目标

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

3) 新建规则

在这里插入图片描述

4) 在 host 1 上传镜像


[root@localhost ~]# vim /usr/lib/systemd/system/docker.service 
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.116.104


[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

[root@localhost ~]# docker login -u admin -p Harbor12345 192.168.116.104
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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 hello-world:latest 192.168.116.104/harbor/hello-world

[root@localhost ~]# docker push 192.168.116.104/harbor/hello-world
The push refers to repository [192.168.116.104/harbor/hello-world]
af0b15c8625b: Layer already exists 
latest: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524
  • 查看是否上传成功

5) 查看复制镜像

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6aSTL2bk-1583145108815)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20200302182717205.png)]

​ 红色框框内,是复制记录

​ 查看是否复制

lhost ~]# docker push 192.168.116.104/harbor/hello-world
The push refers to repository [192.168.116.104/harbor/hello-world]
af0b15c8625b: Layer already exists
latest: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524




- 查看是否上传成功



## 5)	查看复制镜像

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200302183815965.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1J1bnpJeXk=,size_16,color_FFFFFF,t_70)


​	红色框框内,是复制记录

​	查看是否复制

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200302183911845.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1J1bnpJeXk=,size_16,color_FFFFFF,t_70)
发布了13 篇原创文章 · 获赞 2 · 访问量 477

猜你喜欢

转载自blog.csdn.net/RunzIyy/article/details/104617033