harbor 是一个企业级docker 镜像仓库
registry 是docker的私有仓库
安全性比较好
纯命令行操作,没有图形化界面
仓库间镜像同步
由于 registry 私有仓库确定太多,使用 harbor 进行替代
1) proxy: 代理,主要实现对请求的识别和分发,内置的Nginx
判断请求内容,根据请求内容,将求情转发至指定的组件服务
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
启动 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
[root@localhost ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# yum-config-manager --add-repo=http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum makecache fast
[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
[root@localhost ~]# yum -y install docker-ce
[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
[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/
[root@localhost harbor]# vim harbor.cfg
hostname = 192.168.116.104
执行安装脚本
[root@localhost harbor]# ./install.sh
# 以下 为 成功启动
✔ ----Harbor has been installed and started successfully.----
安装完 harbor 之后,会自动进行第一次的启动
docker-compose start
docker-compose stop
建议先关闭重启
docker-compose start
docker-compose stop
harbor 默认的账户密码
账户: admin
密码: Harbor12345
http://192.168.116.104/harbor/projects
[root@localhost harbor]# docker images
[root@localhost ~]# docker tag hello-world:latest 192.168.116.104/harbor/hello-world
[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
[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 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
实现环境:
host 1: 192.168.116.103
harbor1: 192.168.116.104
harbor2: 192.168.116.105
[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
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(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)