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

 

 

如果連接到鏡像倉庫harbor失敗,那么請客戶急忙在docker的配置文件中加上鏡像倉庫IP為授信IP。

路徑:

vi /etc/docker/daemon.json

 

 

 

 增加完倉庫harborIP信息后,重新加載配置,並重啟docker

# systemctl daemon-reload

# systemctl restart docker

 

 

結束,

接下來是安裝,看另一篇。。elk安裝。。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM