在使用功能docker过程中,我们不希望构建的镜像存储于网上,想寄存在本地内网的某个 docker daemon上,但是基础镜仍然需要从网络下载到本地,那么如何将下载的基础镜像,例如centos7 、mysql等,整体打包到文件,然后通过拷贝或者内网传输(ftp, scp ,sftp samba服务等)到另一台docker daemon 下,然后再导入到docker 文件系统中。
一、下载镜像
首先,在联网的一台电脑上,使用docker pull 下载具体的基础镜像
[root@yj138 /]# 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
[root@yj138 /]#
查看当前镜像
[root@yj138 /]# 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
[root@yj138 /]#
二、导出镜像
导出镜像,使用 docker save // Save an image to a tar archive
[root@yj138 /]# 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
[root@yj138 /]# docker save registry.cn-hangzhou.aliyuncs.com/taozhenting/centos7-mysql5.6.39:latest > /具体目录/centos7-mysql.tar
[root@yj138 /]# cd /具体目录 && ls -a
. .. centos7-mysql.tar envi rpmPackages
然后将 tar包,通过拷贝,或者网络 复制到另一台设备上
三、镜像导入
在另一台docker 设备上操作,
[root@jxnx251 hadoop]# docker load --input=/存储目录/centos7-mysql.tar
[root@jxnx251 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
或者
[root@jxnx251 hadoop]# docker load < /home/hadoop/wubaolin/registry.tar
[root@jxnx251 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
[root@jxnx251 hadoop]#
转移成功, 接下来,可使用Dockerfile 基于基础镜像构建新镜像
或者 启动容器添加内容,然后提交容器 新建新的镜像