docker 外部镜像 上传到本地仓库

下载外部镜像,多个节点服务器需要安装的时候再到外网下载,虽然加了加速器,修改镜像源为国内的,但是下载速度还是挺慢。

于是想我们已经安装了镜像仓库,为什么不直接将外部下载的镜像信息上传到本地仓库呢。这样只需要下载一次,然后任何需要使用的机器到本地的仓库下载安装即可。

这里我安装ELK中的L,也就是logstash,需要在每个节点服务器都安装,而这个文件就有800多M,再次下载就比较慢。于是。。这样做了。

 这里我的镜像仓库harbor安装在192.168.89.132上。

上传镜像的格式为 
docker push 192.168.89.132/third/logstash:7.1.1

这里下载外网镜像上传到本地仓库分几步走。

0、在harbor仓库中新建一个第三方项目,专门安装第三方镜像。

使用默认的用户名密码安装。也就是admin/Harbor12345

1、下载外网镜像。

// 文件收集logstash
# docker pull logstash:7.1.1
// 存储,搜索引擎 elasticsearch
# docker pull elasticsearch:7.1.1
// 视图管理
# docker pull kibana:7.1.1
// 日志搬运工 Filebeat
# docker pull filebeat:7.1.1

2、修改镜像名称。

为什么需要修改镜像名,因为我们上传镜像到仓库有他自己的规则

这里其实就是使用docker tag 将标签名称类似复制一份。

url/项目名/镜像名称:标签tag

执行修改镜像命令:

docker打标签格式 

docker tag 镜像ID 镜像名称:标签tag

docker tag b0e9f9f047e6 192.168.89.132/third/elasticsearch:7.1.1
docker tag 67f17df6ca3e 192.168.89.132/third/kibana:7.1.1
docker tag b0cb1543380d 192.168.89.132/third/logstash:7.1.1
docker tag 0bd69a03e199 192.168.89.132/third/filebeat:7.1.1

执行后查询,得到如下结果:打标签完成。

[root@localhost ~]# docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
192.168.89.132/third/logstash        7.1.1               b0cb1543380d        9 months ago        847MB
logstash                             7.1.1               b0cb1543380d        9 months ago        847MB
192.168.89.132/third/kibana          7.1.1               67f17df6ca3e        9 months ago        746MB
kibana                               7.1.1               67f17df6ca3e        9 months ago        746MB
elasticsearch                        7.1.1               b0e9f9f047e6        9 months ago        894MB
192.168.89.132/third/elasticsearch   7.1.1               b0e9f9f047e6        9 months ago        894MB
192.168.89.132/third/filebeat        7.1.1               0bd69a03e199        9 months ago        288MB
store/elastic/filebeat               7.1.1               0bd69a03e199        9 months ago        288MB
java                                 8                   d23bdf5b1b1b        3 years ago         643MB

如果名称错了,可以通过删除镜像的方法删除

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
logstash 7.1.1 b0cb1543380d 9 months ago 847MB
elk_logstash 7.1.1 b0cb1543380d 9 months ago 847MB

例如之前我名称错误,为elk_logstash,现在将结果删除,虽然提示Untagged,但是,实际上已经是删除了。

[root@localhost ~]# docker rmi elk_logstash:7.1.1
Untagged: elk_kibana:7.1.1

3、上传到本地镜像。

执行上传命令,上传可分两种,一种是ssh互信。一种是用户名密码。

这里我使用用户名密码方式,比较简单。

上传的时候注意,登录一次,可上传多次。

这里上传 logstash

//登录
# docker login -u admin -p Harbor12345 192.168.89.132
// 上传
# docker push 192.168.89.132/third/logstash:7.1.1

上传中。

 最终结果如下:

[root@localhost ~]# docker push 192.168.89.132/third/logstash:7.1.1
The push refers to repository [192.168.89.132/third/logstash]
91c7e8dbdc32: Pushed
3fb6d42ca421: Pushed
09680c30f949: Pushed
0832e33a1e70: Pushed
c8d021d02b9d: Pushed
6ec82ef47616: Pushed
b88ec0fc0928: Pushed
a11616483e9b: Pushed
0f5ddbf38e72: Pushed
075d8d70823f: Pushed
d69483a6face: Mounted from third/elasticsearch
7.1.1: digest: sha256:fd77ebe9cc5c9e7c04532db6bed92a80a15cc32de91fb3a3d74ee5f6aaf2878c size: 2824

其他几个镜像也一并上传

docker push 192.168.89.132/third/elasticsearch:7.1.1
docker push 192.168.89.132/third/kibana:7.1.1
docker push 192.168.89.132/third/filebeat:7.1.1

4、登录镜像仓库查看上传结果

通过浏览器登录镜像仓库查看third项目

http://192.168.89.132/

看到我刚刚上传的镜像都已经到了仓库中了。

5、到其他服务器去安装上传到本地的镜像

现在到另一个服务器节点 192.168.89.133

通过 命令查看当前镜像为空

[root@slave2 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@slave2 ~]# 

要安装镜像仓库的镜像,那么需要先登录仓库否则直接下载是不行的。

[root@slave2 ~]# docker pull 192.168.89.132/third/logstash:7.1.1
Error 。。。。。。。

需要与上传一样,先登录后上传。 

# docker login -u admin -p Harbor12345 192.168.89.132

# docker pull 192.168.89.132/third/logstash:7.1.1

查看镜像信息

[root@localhost ~]# docker pull 192.168.89.132/third/logstash:7.1.1
7.1.1: Pulling from third/logstash
8ba884070f61: Pull complete 
f98cc5c12838: Pull complete 
487aaccc47c9: Pull complete 
5de63618f178: Pull complete 
f1e707488ca5: Pull complete 
2f538e5fa043: Pull complete 
bc578c9b5b8a: Pull complete 
9d08fc60ede0: Pull complete 
ec847b96ea11: Pull complete 
467f46a19db9: Pull complete 
500547df61cd: Pull complete 
Digest: sha256:fd77ebe9cc5c9e7c04532db6bed92a80a15cc32de91fb3a3d74ee5f6aaf2878c
Status: Downloaded newer image for 192.168.89.132/third/logstash:7.1.1
192.168.89.132/third/logstash:7.1.1

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.89.132/third/logstash 7.1.1 b0cb1543380d 9 months ago 847MB

 

结束,

接下来是安装,看另一篇。。elk安装。。

猜你喜欢

转载自www.cnblogs.com/a393060727/p/12326023.html
今日推荐