docker镜像文件的导入与导出(docker镜像迁移)

1、查看镜像ID

# docker images

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mytomcat 1.0 f8ec6dad9608 minutes ago 612MB
centos latest 1e1148e4cc2c weeks ago 202MB

2、选择要打包的镜像,执行打包命令

docker save : 将指定镜像保存成 tar 归档文件

语法:

docker save [options] image [image……]

options

-o :输出到的文件。

# docker save -o mytomcat.tar mytomcat:1.0

[root@localhost ~]# docker save -o mytomcat.tar mytomcat:1.0
[root@localhost ~]#
[root@localhost ~]# ls
anaconda-ks.cfg mytomcat.tar

3、scp远程复制到迁移的另一台服务器上

# scp -r mytomcat.tar root@192.168.2.207:/root/

[root@localhost ~]# scp -r mytomcat.tar root@192.168.2.207:/root/
The authenticity of host '192.168.2.207 (192.168.2.207)' can't be established.
ECDSA key fingerprint is fa:8c:a3:e2::7e:cc:be:1e:::6a:e7::de:.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.207' (ECDSA) to the list of known hosts.
root@192.168.2.207's password:
mytomcat.tar % 594MB .6MB/s :
[root@localhost ~]#

4、到另一台服务器上导入

查看已有的镜像

# docker images

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 102816b1ee7d weeks ago 486MB

导入镜像

# docker load -i mytomcat.tar

[root@localhost ~]# ls
mytomcat.tar software
[root@localhost ~]#
[root@localhost ~]# docker load -i mytomcat.tar
071d8bd76517: Loading layer [==================================================>] .2MB/.2MB
cc30c42de5c4: Loading layer [==================================================>] .5MB/.5MB
Loaded image: mytomcat:1.0
[root@localhost ~]#

查看是否成功导入

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mytomcat 1.0 f8ec6dad9608 Less than a second ago 612MB
mysql latest 102816b1ee7d weeks ago 486MB

end

上一篇:一文看懂npm、yarn、pnpm之间的区别


下一篇:STL六大组件