1. 环境准备
1.1. 安装docker
链接:https://blog.csdn.net/m0_46674735/article/details/111690794
1.2 安装docker-compose
链接: https://blog.csdn.net/m0_46674735/article/details/111799167
2. harbor 安装和部署:
2.1 harbor 软件包下载地址
链接:https://github.com/goharbor/harbor/releases
2.2 上传并解压harbor软件包
[root@localhost ~]# tar xzf harbor-offline-installer-v1.9.4.tgz -C /usr/local/
2.3 修改harbor的配置文件
2.3.1 切换到harbor目录下修改配置文件
[root@localhost ~]# cd /usr/local/harbor/
[root@localhost harbor]# vim harbor.yml
2.3.2 修改以下内容
要访问的IP地址
访问的端口(默认为80)
管理员初始登录密码
修改完成后保存退出
2.4 执行安装脚本
2.4.1 首次安装需要导入很多镜像,时间较长,耐心等待即可,
2.4.2 最终出现如下提示,说明部署成功
2.4.3 查看容器状态,当容器状态全部为healthy时,说明容器初始化完毕,浏览器即可访问
2.5 浏览器登录harbor
2.5.1 登录
2.5.2 修改语言为简体中文
3. 在harbor中新建项目并上传镜像
**新建项目名为docker,访问级别为公开
查看创建成功
3.1 向harbor中推送mysql镜像
推送镜像可以在任何一个可以访问harbor的docker主机上操作
在IP地址为 192.168.153.189的主机上进行操作
3.1.1 修改docker的配置文件
[root@localhost ~]# vim /etc/docker/daemon.json
修改内容如下:
3.1.2 修改保存退出之后重启docker
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
3.1.3 登录harbor,输入harbor管理员账号和密码(设置均为admin)
3.1.4 给mysql镜像加一个包含harbor仓库ip和项目的标签
[root@localhost ~]# docker tag mysql:5.7 192.168.153.188/docker/mysql:5.7
3.1.5 推送镜像,执行docker push 镜像名字:标签,即可完成推送
[root@localhost ~]# docker push 192.168.153.188/docker/mysql:5.7
The push refers to repository [192.168.153.188/docker/mysql]
6c316520569e: Pushed
f6bef35c0067: Pushed
a6ea401b7864: Pushed
94bd7d7999de: Pushed
8df989cb6670: Pushed
f358b00d8ce7: Pushed
ae39983d39c4: Pushed
b55e8d7c5659: Pushed
e8fd11b2289c: Pushed
e9affce9cbe8: Pushed
316393412e04: Pushed
d0f104dc0a1f: Pushed
5.7: digest: sha256:b9c1994c82f94c13370b0d79efa703616a538bf55fcb7e0923892d5a5e753514 size: 2829
3.1.6 登录harbor查看docker项目中是否有mysql镜像
3.2 从harbor中拉取mysql镜像
如需要从harbor仓库中下载镜像的话,也需要向 3.1.1 中修改docker的daemon.json文件,修改完成后重启动车客人服务,之前已经修改,所以不需要再修改
3.2.1 删除本地的mysql镜像
[root@localhost ~]# docker rmi mysql:5.7
Untagged: mysql:5.7
[root@localhost ~]# docker rmi 192.168.153.188/docker/mysql:5.7
Untagged: 192.168.153.188/docker/mysql:5.7
Untagged: 192.168.153.188/docker/mysql@sha256:b9c1994c82f94c13370b0d79efa703616a538bf55fcb7e0923892d5a5e753514
Deleted: sha256:a4cc8ac4386762cd0e8e3d9c7ca4ba6e84898aff2995762baaf47aef8cbaf063
Deleted: sha256:58943f97772ae5603ec8a3d9ca0e1795361be5f5219e607907dd3bc36c40c024
Deleted: sha256:058d93ef2bfb943ba6a19d8b679c702be96e34337901da9e1a07ad62b772bf3d
Deleted: sha256:7bca77783fcf15499a0386127dd7d5c679328a21b6566c8be861ba424ac13e49
Deleted: sha256:183d05512fa88dfa8c17abb9b6f09a79922d9e9ee001a33ef34d1bc094bf8f9f
Deleted: sha256:165805124136fdee738ed19021a522bb53de75c2ca9b6ca87076f51c27385fd7
Deleted: sha256:904abdc2d0bea0edbb1a8171d1a1353fa6de22150a9c5d81358799a5b6c38c8d
Deleted: sha256:d26f7649f78cf789267fbbca8aeb234932e230109c728632c6b9fbc60ca5591b
Deleted: sha256:7fcf7796e23ea5b42eb3bbd5bec160ba5f5f47ecb239053762f9cf766c143942
Deleted: sha256:826130797a5760bcd2bb19a6c6d92b5f4860bbffbfa954f5d3fc627904a76e9d
Deleted: sha256:53e0181c63e41fb85bce681ec8aadfa323cd00f70509107f7001a1d0614e5adf
Deleted: sha256:d6854b83e83d7eb48fb0ef778c58a8b839adb932dd036a085d94a7c2db98f890
Deleted: sha256:d0f104dc0a1f9c744b65b23b3fd4d4d3236b4656e67f776fe13f8ad8423b955c
[root@localhost ~]#
3.2.2 从harbor仓库中拉取镜像
[root@localhost ~]# docker pull 192.168.153.188/docker/mysql:5.7
5.7: Pulling from docker/mysql
bf5952930446: Pull complete
8254623a9871: Pull complete
938e3e06dac4: Pull complete
ea28ebf28884: Pull complete
f3cef38785c2: Pull complete
894f9792565a: Pull complete
1d8a57523420: Pull complete
5f09bf1d31c1: Pull complete
1b6ff254abe7: Pull complete
74310a0bf42d: Pull complete
d398726627fd: Pull complete
784aa83a1bf2: Pull complete
Digest: sha256:b9c1994c82f94c13370b0d79efa703616a538bf55fcb7e0923892d5a5e753514
Status: Downloaded newer image for 192.168.153.188/docker/mysql:5.7
192.168.153.188/docker/mysql:5.7
查看拉取成功
[root@localhost ~]# docker images |grep mysql
192.168.153.188/docker/mysql 5.7 a4cc8ac43867 4 months ago 448MB