天天看點

docker 鏡像的導出與導入一、下載下傳鏡像二、導出鏡像三、鏡像導入

     在使用功能docker過程中,我們不希望建構的鏡像存儲于網上,想寄存在本地内網的某個 docker daemon上,但是基礎鏡仍然需要從網絡下載下傳到本地,那麼如何将下載下傳的基礎鏡像,例如centos7 、mysql等,整體打包到檔案,然後通過拷貝或者内網傳輸(ftp, scp ,sftp samba服務等)到另一台docker daemon 下,然後再導入到docker 檔案系統中。

一、下載下傳鏡像

 首先,在聯網的一台電腦上,使用docker pull  下載下傳具體的基礎鏡像

[[email protected] /]# docker pull registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39
latest: Pulling from registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39
72a57cd6f59e: Downloading [=====>                                             ] 7.367 MB/73.17 MB
437b26967a35: Download complete 
404643e1b09d: Download complete 
8c1df8e84e1e: Download complete 
ed011b4cefad: Download complete 
a29a91270ab9: Download complete 
cc7e0c733682: Download complete 
44f06e627506: Download complete 
c765eb323142: Downloading [========>                                          ] 8.971 MB/56 MB
6c947b94fe88: Download complete 
bb247c4659f5: Download complete 
651e62357935: Download complete 
f79735d0a128: Download complete 
49a860dfa73f: Download complete 
e1f145d014a1: Download complete 
ea7ef0491107: Downloading [=>                                                 ]  7.39 MB/192.6 MB
c0c38974ac7d: Download complete 
2c1cd91dcafd: Download complete 
22a5a8f2f2ab: Download complete 
           

下載下傳完成後,

latest: Pulling from registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39
72a57cd6f59e: Pull complete 
437b26967a35: Pull complete 
404643e1b09d: Pull complete 
8c1df8e84e1e: Pull complete 
ed011b4cefad: Pull complete 
a29a91270ab9: Pull complete 
cc7e0c733682: Pull complete 
44f06e627506: Pull complete 
c765eb323142: Pull complete 
6c947b94fe88: Pull complete 
bb247c4659f5: Pull complete 
651e62357935: Pull complete 
f79735d0a128: Pull complete 
49a860dfa73f: Pull complete 
e1f145d014a1: Pull complete 
ea7ef0491107: Pull complete 
c0c38974ac7d: Pull complete 
2c1cd91dcafd: Pull complete 
22a5a8f2f2ab: Pull complete 
Digest: sha256:1d907d061ee7b1a41c0f42966b9625e6f6da4cc9da0017602c6cef39eb696312
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39:latest
[[email protected] /]# 
           

檢視目前鏡像

[[email protected] /]# docker images
REPOSITORY                                                          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39   latest              22a5a8f2f2ab        7 months ago        933.5 MB
registry.cn-hangzhou.aliyuncs.com/marmot/mysql-5.6                  latest              06cf43840fdb        11 months ago       299 MB
[[email protected] /]# 
           

二、導出鏡像

導出鏡像,使用 docker   save      // Save an image to a tar archive

[[email protected] /]# docker images
REPOSITORY                                                          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39   latest              22a5a8f2f2ab        7 months ago        933.5 MB
registry.cn-hangzhou.aliyuncs.com/marmot/mysql-5.6                  latest              06cf43840fdb        11 months ago       299 MB
[[email protected] /]# docker save registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39:latest > /具體目錄/centos7-mysql.tar
[[email protected] /]# cd /具體目錄 && ls -a
.  ..  centos7-mysql.tar  envi  rpmPackages
           

然後将 tar包,通過拷貝,或者網絡  複制到另一台裝置上

三、鏡像導入

在另一台docker 裝置上操作,

[[email protected] hadoop]# docker load  --input=/存儲目錄/centos7-mysql.tar
[[email protected] hadoop]# docker images
REPOSITORY                                                          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39   latest              22a5a8f2f2ab        7 months ago        815.5 MB
           

或者

[[email protected] hadoop]# docker load < /home/hadoop/wubaolin/registry.tar
[[email protected] hadoop]# docker images
REPOSITORY                                                          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
daocloud.io/registry                                                latest              642c5398c648        12 weeks ago        33.29 MB
registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39   latest              22a5a8f2f2ab        7 months ago        815.5 MB
[[email protected] hadoop]# 
           

轉移成功, 接下來,可使用Dockerfile  基于基礎鏡像建構新鏡像

或者  啟動容器添加内容,然後送出容器 建立新的鏡像