首页 > 其他分享 >10,docker基础之---Harbor+阿里云+本地镜像仓库

10,docker基础之---Harbor+阿里云+本地镜像仓库

时间:2023-03-06 21:31:37浏览次数:59  
标签:ago 10 Harbor --- harbor mysql -- docker root

什么是镜像仓库?

存放着很多镜像的仓库。

为什么要使用镜像仓库?

例如我们之前使用的pull下载mysql镜像的时候下载的镜像就是存放在他人的镜像仓库之上,公司内部部署镜像仓库即可多台电脑从此库中拉取镜像进行使用。

镜像仓库的分类(大致分两类)

公共镜像仓库:【官方​​https://hub.docker.com​​】【非官方:基于其他组织开发的免费镜像供大家学习和使用】

私有镜像仓库: 公司自己搭建的,用于存放公司内部的镜像,自己管理,不提供给外部使用。

阿里云镜像仓库的搭建使用

阿里云镜像仓库申请地址:

https://cr.console.aliyun.com/cn-hangzhou/instance/repositories

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql

10,docker基础之---Harbor+阿里云+本地镜像仓库_centos_02

10,docker基础之---Harbor+阿里云+本地镜像仓库_centos_03

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_04

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_05

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_06

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_07

10,docker基础之---Harbor+阿里云+本地镜像仓库_docker_08


上述则是创建完成操作指南表示分几个步骤下面我对以下内容进行实战操作
[root@docker ~]# docker login --username=aliyun5965972577 registry.cn-hangzhou.aliyuncs.com
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@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentos redis b7aa4955980a 3 days ago 599MB
mycentos nginx 1cdfb823cd10 3 days ago 522MB
mycentos jdk 27177c9bb814 3 days ago 1.04GB
wordpress latest c3c92cc3dcb1 14 months ago 616MB
mysql 5.7 c20987f18b13 14 months ago 448MB
centos 7 eeb6ee3f44bd 17 months ago 204MB
[root@docker ~]#如我想把上述的mysql:5.7上传到阿里云镜像
[root@docker ~]# docker tag c20987f18b13 registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql:5.7
#再次进行查看倒数第二行已经上传成功
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentos redis b7aa4955980a 3 days ago 599MB
mycentos nginx 1cdfb823cd10 3 days ago 522MB
mycentos jdk 27177c9bb814 3 days ago 1.04GB
wordpress latest c3c92cc3dcb1 14 months ago 616MB
mysql 5.7 c20987f18b13 14 months ago 448MB
registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql 5.7 c20987f18b13 14 months ago 448MB
centos 7 eeb6ee3f44bd 17 months ago 204MB
[root@docker ~]# docker push registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql:5.7
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql]
e889c671872c: Pushed
789f3aa31b3f: Pushed
35ba198e64f5: Pushed
9b64bb048d04: Pushed
aad27784b762: Pushed
0d17fee8db40: Pushed
d7a777f6c3a4: Pushed
a0c2a050fee2: Pushed
0798f2528e83: Pushed
fba7b131c5c3: Pushed
ad6b69b54919: Pushed
5.7: digest: sha256:398f124948bb3d5789c0ac7c004d02e6d9a3ae95aa9804d7a3b33a344ff3c9cd size: 2621
[root@docker ~]#

上传成功咱们进入到阿里云仓库去看一下:

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_09

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_10

下面新开一台虚拟机进行测试(宿主机为192.168.88新开一台为192.168.88.188)

#188ip先登录阿里云
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 eeb6ee3f44bd 17 months ago 204MB
[root@localhost ~]# docker login --username=aliyun5965972577 registry.cn-hangzhou.aliyuncs.com
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 pull registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql:5.7
5.7: Pulling from lyxceshi/mysql
72a69066d2fe: Pull complete
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
0ceb82207cd7: Pull complete
37f2405cae96: Pull complete
e2482e017e53: Pull complete
70deed891d42: Pull complete
Digest: sha256:398f124948bb3d5789c0ac7c004d02e6d9a3ae95aa9804d7a3b33a344ff3c9cd
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql:5.7
registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql:5.7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql 5.7 c20987f18b13 14 months ago 448MB
centos 7 eeb6ee3f44bd 17 months ago 204MB
[root@localhost ~]#

修改名称:

[root@localhost ~]# docker tag  registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql:5.7 mysql:5.7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 c20987f18b13 14 months ago 448MB
registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql 5.7 c20987f18b13 14 months ago 448MB
centos 7 eeb6ee3f44bd 17 months ago 204MB
[root@localhost ~]#

启动mysql容器:

[root@localhost ~]# docker run -itd mysql:5.7 /bin/bash
0cc36629e1bd8449fb9a202d25a4f65378062edb6a6c5b492a745334c7022cf5
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0cc36629e1bd mysql:5.7 "docker-entrypoint.s…" 19 seconds ago Up 18 seconds 3306/tcp, 33060/tcp mystifying_banach
[root@localhost ~]#

harbor镜像仓库搭建

简介:构建自己的镜像仓库

前提:安装之前确保前置条件满足,需要安装docker,docker-compose,openssl以及python2.7以上

harbor离线版安装下载地址:

https://github.com/goharbor/harbor/releases

安装依赖环境包:

[root@docker ~]# yum install openssl -y

上传harbor安装包到/usr/local

[root@docker ~]# cd /usr/local/
[root@docker local]# ll
总用量 620080
drwxr-xr-x. 2 root root 28 2月 17 19:51 bin
drwxr-xr-x. 2 root root 6 4月 11 2018 etc
drwxr-xr-x. 2 root root 6 4月 11 2018 games
-rw-r--r-- 1 root root 634959522 2月 19 16:10 harbor-offline-installer-v1.9.3.tgz
drwxr-xr-x. 2 root root 6 4月 11 2018 include
drwxr-xr-x. 2 root root 6 4月 11 2018 lib
drwxr-xr-x. 2 root root 6 4月 11 2018 lib64
drwxr-xr-x. 2 root root 6 4月 11 2018 libexec
drwxr-xr-x. 2 root root 6 4月 11 2018 sbin
drwxr-xr-x. 5 root root 49 11月 21 17:57 share
drwxr-xr-x. 2 root root 6 4月 11 2018 src
[root@docker local]#

进行解压:

[root@docker local]# tar -xf harbor-offline-installer-v1.9.3.tgz

进入解压完成的harbor目录修改配置文件harbor.yml:

[root@docker local]# cd harbor
[root@docker harbor]# ll
总用量 623364
-rw-r--r-- 1 root root 638288840 11月 14 2019 harbor.v1.9.3.tar.gz
-rw-r--r-- 1 root root 5805 11月 14 2019 harbor.yml
-rwxr-xr-x 1 root root 5088 11月 14 2019 install.sh
-rw-r--r-- 1 root root 11347 11月 14 2019 LICENSE
-rwxr-xr-x 1 root root 1748 11月 14 2019 prepare
[root@docker harbor]#

修改harbor.yml文件内的主机名和密码:

[root@docker harbor]# vim harbor.yml
#修改第四行为IP
原内容:
hostname: reg.mydomain.com
修改后:
hostname: r192.168.88.88

#修改第27行密码
原内容密码为默认arbor12345可以自行进行修改
harbor_admin_password: Harbor12345

执行prepare脚本:

[root@docker harbor]# sh prepare

ll查看一下是否生成一个docker-compose.yml文件

[root@docker harbor]# ll
总用量 623372
drwxr-xr-x 3 root root 20 2月 19 16:22 common
-rw-r--r-- 1 root root 5290 2月 19 16:22 docker-compose.yml
-rw-r--r-- 1 root root 638288840 11月 14 2019 harbor.v1.9.3.tar.gz
-rw-r--r-- 1 root root 5802 2月 19 16:18 harbor.yml
-rwxr-xr-x 1 root root 5088 11月 14 2019 install.sh
-rw-r--r-- 1 root root 11347 11月 14 2019 LICENSE
-rwxr-xr-x 1 root root 1748 11月 14 2019 prepare
[root@docker harbor]#

安装install.sh:

[root@docker harbor]# sh install.sh

查看:

[root@docker harbor]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------
harbor-core /harbor/harbor_core Up (healthy)
harbor-db /docker-entrypoint.sh Up (healthy) 5432/tcp
harbor-jobservice /harbor/harbor_jobservice ... Up (healthy)
harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp
harbor-portal nginx -g daemon off; Up (healthy) 8080/tcp
nginx nginx -g daemon off; Up (healthy) 0.0.0.0:80->8080/tcp,:::80->8080/tcp
redis redis-server /etc/redis.conf Up (healthy) 6379/tcp
registry /entrypoint.sh /etc/regist ... Up (healthy) 5000/tcp
registryctl /harbor/start.sh Up (healthy)
[root@docker harbor]#

输入本机地址进入浏览器访问验证:

10,docker基础之---Harbor+阿里云+本地镜像仓库_centos_11

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_12

harbor镜像仓库使用

使用另一台centos当作客户端进行访问:

[root@localhost ~]# docker login --username=admin 192.168.88.88
Password:
Error response from daemon: Get "https://192.168.88.88/v2/": dial tcp 192.168.88.88:443: connect: no route to host
[root@localhost ~]#发现登录失败这是因为harbor是https协议需要进行修改客户端

修改配置文件添加私有仓库地址:

[root@localhost ~]# vi /etc/docker/daemon.json
追加,"insecure-registries":["http://192.168.88.88"]
#原内容
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://jc5mcdvz.mirror.aliyuncs.com"]
}
#修改后内容
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://jc5mcdvz.mirror.aliyuncs.com"],"insecure-registries":["http://192.168.88.88"]
}
[root@localhost ~]# "insecure-registries":["http://192.168.0.151"]

进行重启docker服务:

[root@localhost ~]# systemctl restart docker

再次进行登录:

[root@localhost ~]# docker login --username=admin 192.168.88.88
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 ~]#

在网页新创建一下项目:

10,docker基础之---Harbor+阿里云+本地镜像仓库_centos_13

10,docker基础之---Harbor+阿里云+本地镜像仓库_centos_14

10,docker基础之---Harbor+阿里云+本地镜像仓库_docker_15

10,docker基础之---Harbor+阿里云+本地镜像仓库_docker_16

进行推送:(客户端测试上传mysql)

[root@localhost ~]# docker tag mysql:5.7 192.168.88.88/lyxceshi/mysql:5.7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.88.88/lyxceshi/mysql 5.7 c20987f18b13 14 months ago 448MB
mysql 5.7 c20987f18b13 14 months ago 448MB
registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql 5.7 c20987f18b13 14 months ago 448MB
centos 7 eeb6ee3f44bd 17 months ago 204MB
[root@localhost ~]#

进行推送:

[root@localhost ~]# docker push 192.168.88.88/lyxceshi/mysql:5.7

10,docker基础之---Harbor+阿里云+本地镜像仓库_docker_17

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_18

服务器进行下载测试:

[root@docker harbor]# vi /etc/docker/daemon.json
[root@docker harbor]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://jc5mcdvz.mirror.aliyuncs.com"],"insecure-registries":["http://192.168.88.88"]
}
[root@docker harbor]#

进行重启docker服务和harbor服务:

[root@docker harbor]# systemctl restart docker
[root@docker harbor]# docker-compose up -d

进入容器:

[root@docker harbor]# docker login --username=admin 192.168.88.88
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@docker harbor]#

进行下载:

[root@docker harbor]# docker pull 192.168.88.88/lyxceshi/mysql:5.7


10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_19

还可以设置公开如下:

10,docker基础之---Harbor+阿里云+本地镜像仓库_mysql_20

刚才咱们已经登录进入镜像该如何退出呢如下:

[root@docker harbor]# docker logout
Removing login credentials for https://index.docker.io/v1/
[root@docker harbor]#

再次进入登录:

[root@docker harbor]# docker login --username=admin 192.168.88.88
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/.docker/config.json.我们可以查看一下也可以给这个文件删除
[root@docker harbor]# cat /root/.docker/config.json
{
"auths": {
"192.168.88.88": {
"auth": "YWRtaW46SGFyYm9yMTIzNDU="
}
}
}[root@docker harbor]#进行删除1
[root@docker harbor]# rm -rf /root/.docker/config.json

本地镜像仓库创建使用

#查看镜像
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentos redis b7aa4955980a 3 days ago 599MB
mycentos nginx 1cdfb823cd10 3 days ago 522MB
mycentos jdk 27177c9bb814 4 days ago 1.04GB
mysql 5.7 c20987f18b13 14 months ago 448MB
centos 7 eeb6ee3f44bd 17 months ago 204MB
#进行保存
[root@docker ~]# docker save c20987f18b13 -o /home/mysql.tar

#详解
docker save 进行保存
c20987f18b13 mysql的ID也可以直接输入mysql:5.7
-o 表示输出
/home/mysql.tar 表示输出的目录

总体也可以上述替换成
[root@docker ~]# docker save mysql:5.7 > /home/mysql.tar

进行查看:

[root@docker ~]# cd /home/
[root@docker home]# ll
总用量 444804
-rw-r--r-- 1 root root 179 2月 16 09:28 dockerfile
-rw------- 1 root root 453726720 2月 19 17:30 mysql.tar
drwxrwxr-x 6 root root 309 3月 27 2018 redis-4.0.9
-rw-r--r-- 1 root root 1737022 2月 16 09:27 redis-4.0.9.tar.gz
-rw-r--r-- 1 root root 219 2月 16 09:28 redis_install.sh
[root@docker home]#

载入镜像:

#本地传输到宿主机
[root@docker home]# sz mysql.tar

下载好之后打开另一台虚拟机进行载入镜像:

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 c20987f18b13 14 months ago 448MB
registry.cn-hangzhou.aliyuncs.com/lyxceshi/mysql 5.7 c20987f18b13 14 months ago 448MB
centos 7 eeb6ee3f44bd 17 months ago 204MB
[root@localhost ~]#把上述的mysql镜像先进行删除处理
[root@localhost ~]# docker rmi -f c20987f18b13
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 eeb6ee3f44bd 17 months ago 204MB

进行载入:

[root@localhost ~]# ll   上传成功
total 431368
-rw-------. 1 root root 1260 Nov 21 05:08 anaconda-ks.cfg
-rw-r--r-- 1 root root 441714176 Feb 19 04:41 mysql.tar
[root@localhost ~]#

对mysql.tar进行载入:

[root@localhost ~]# docker load -i mysql.tar
#其中的-i也可以替换成小于号<
#进行查看
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 eeb6ee3f44bd 17 months ago 204MB
<none> <none> cd3ed0dfff7e 3 years ago 437MB
[root@localhost ~]#发现载入成功但是没有名字我们来对他进行修改
[root@localhost ~]# docker tag cd3ed0dfff7e mysql:5.7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 eeb6ee3f44bd 17 months ago 204MB
mysql 5.7 cd3ed0dfff7e 3 years ago 437MB
[root@localhost ~]#发现已经ok了(ID也是一样的原封不动复制过来)

保存容器:

#启动一个mysql容器
[root@docker home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentos redis b7aa4955980a 3 days ago 599MB
mycentos nginx 1cdfb823cd10 3 days ago 522MB
mycentos jdk 27177c9bb814 4 days ago 1.04GB
mysql 5.7 c20987f18b13 14 months ago 448MB
centos 7 eeb6ee3f44bd 17 months ago 204MB
[root@docker home]# docker run -itd c20987f18b13 /bin/bash
111400433a3b707eaca9fc7c27b3d16219566d710224db1b2dbc7762497e1e24
[root@docker home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
111400433a3b c20987f18b13 "docker-entrypoint.s…" 15 seconds ago Up 14 seconds 3306/tcp, 33060/tcp cool_tharp
[root@docker home]#

进行载入:

[root@docker home]# docker export 111400433a3b -o /home/mysql-export.tar
[root@docker home]# ll
总用量 881604
-rw-r--r-- 1 root root 179 2月 16 09:28 dockerfile
-rw------- 1 root root 447279616 2月 19 17:53 mysql-export.tar
-rw------- 1 root root 453726720 2月 19 17:30 mysql.tar
drwxrwxr-x 6 root root 309 3月 27 2018 redis-4.0.9
-rw-r--r-- 1 root root 1737022 2月 16 09:27 redis-4.0.9.tar.gz
-rw-r--r-- 1 root root 219 2月 16 09:28 redis_install.sh
[root@docker home]#进行下载到宿主机
[root@docker home]# sz mysql-export.tar

另一台服务器进行载入此容器:

#进行上传:
[root@localhost ~]# ll
total 481596
-rw-------. 1 root root 1260 Nov 21 05:08 anaconda-ks.cfg
-rw-r--r-- 1 root root 51433090 Feb 19 04:56 mysql-export.tar
-rw-r--r-- 1 root root 441714176 Feb 19 04:41 mysql.tar
[root@localhost ~]#进行载入
[root@localhost ~]# docker import mysql-export.tar
#ok之后查看镜像发现ID与之前ID不一样也就是说这样的方法则不是完完全全复制而是可以自动生成


标签:ago,10,Harbor,---,harbor,mysql,--,docker,root
From: https://blog.51cto.com/lyx888/6104030

相关文章

  • 贝叶斯方法发挥作用案例 - 天蝎号核潜艇搜救
    作为当时美国海军大西洋舰队的19艘核动力攻击潜艇之一,排水量3000吨的天蝎号属于飞鱼级核潜艇。为了最大限度的提升水下速度,该艇采用了先进的泪滴形外壳,以33节(每小时61公里)......
  • 逆向软件设计和开发能力-----学籍管理系统
    逆向工程是一种产品设计技术再现过程。也是一个合格的程序员必不可少的技能,在更新进步软件和维护软件方面功不可没。我找到了我曾经自己写的“学籍管理系统”并为它画出系......
  • 2.ubuntu-22.10
    1.开始安装2.选择中文3.键盘布局选择chinese4.更新和其他软件5.安装类型选择默认的”清除整个磁盘“6.时区选择"shanghai"7.设置密码,等待安装8.若提示:Pl......
  • 【Mybatis】【SQL执行过程】【二】Mybatis源码解析-Mapper代理执行逻辑
    1 前言上节我们回顾了下Mapper接口的解析存放以及代理的入口和创建代理的过程,那么这节我们就来看下MapperProxy的代理执行逻辑。2 源码分析2.1 invoke代理逻......
  • csp201709-2
    题目:计算机软件能力认证考试系统直接对时间进行枚举,本以为会超时,没想到过了,过了就过了、、 #include<bits/stdc++.h>usingnamespacestd;set<int>keep[10105];se......
  • Book-深入设计模式-中介者模式
    Book-深入设计模式-中介者模式https://refactoringguru.cn/design-patterns/mediator中介者模式亦称:调解人、控制器、Intermediary、Controller、Mediator中介者模式......
  • 2023-3.6-课堂演示-加0.5分
    2023年3月6日,演示,加0.5。今天下午我们上了软工课程,在课上我演示了自己开发的安卓APP,获得加0.5分的奖励。王老师让我们发博客用来记录和证明加分的存在。 我演示的app......
  • 日本人教的AXI4-Lite总线课程
    地址:https://www.bilibili.com/video/BV1364y117ZB/?spm_id_from=333.788.recommend_more_video.-1&vd_source=7a1a0bc74158c6993c7355c5490fc600AXI4-Lite传输的三种时......
  • PAT Basic 1009. 说反话
    PATBasic1009.说反话1.题目描述:给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。2.输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的......
  • 【django-vue】登录注册模态框分析 登录注册前端页面 腾讯短信功能二次封装 短信验证
    目录昨日回顾csrf跨站请求伪造接口幂等性异常捕获今日内容1登录注册模态框分析Login.vueHeader.vue2登录注册前端页面复制2.0Header.vue2.1Login.vue2.2Register.vue3......