Docker的备份方式有export和save两种。
export是当前的状态,针对的是容器,docker save 是针对镜像images。
1.镜像保存
登陆到已经部署好镜像的服务器上面,执行以下命令进行导出
[root@mytest2 local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
shiyu/centos tomcat-centos b61b207a5809 28 minutes ago 1.263 GB
docker.io/centos latest 2d194b392dd1 7 hours ago 195.4 MB
docker.io/centos 7.3.1611 66ee80d59a68 4 months ago 191.8 MB
[root@mytest2 local]# docker save b61b >mytomcat.tar
2.将镜像导入
将刚才导出的镜像上传到你要导入的那台服务器上
[root@mytest local]# scp mytomcat.tar 192.168.0.4:/usr/local/
root@192.168.0.4's password:
mytomcat.tar 100% 1228MB 49.1MB/s 00:25
执行以下命令镜像导入
[root@mytest local]# ll mytomcat.tar
-rw-r--r-- 1 root root 1287580160 Mar 6 16:36 mytomcat.tar
[root@mytest local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@mytest local]# docker load < mytomcat.tar
b03095563b79: Loading layer [==================================================>] 204 MB/204 MB
1d88d689ca13: Loading layer [==================================================>] 3.584 kB/3.584 kB
a997e4440673: Loading layer [==================================================>] 2.56 kB/2.56 kB
0a3b6c7be500: Loading layer [==================================================>] 309.5 MB/309.5 MB
cee5bf38dfe0: Loading layer [==================================================>] 774.1 MB/774.1 MB
Loaded image ID: sha256:b61b207a5809e56150df90e9c419f838c9a0988828773ef33aa2768e589c19c2kB/774.1 MB
[root@mytest local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> b61b207a5809 About an hour ago 1.263 GB
[root@mytest local]# docker tag b61b mytomcat:2.0
[root@mytest local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mytomcat 2.0 b61b207a5809 About an hour ago 1.263 G
1.导出容器
[root@mytest2 local]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8578122af714 b61b "/bin/sh -c '/usr/loc" 56 minutes ago Up 56 minutes 0.0.0.0:8090->8088/tcp naughty_bartik
[root@mytest2 local]# docker export 8578122af714 > mytomcat_export.tar
2.导入到新的服务器上
同样需要将刚才的导出的容器备份上传到目标服务器上,执行下面的命令
[root@mytest local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@mytest local]# cat mytomcat_export.tar |docker import - centos:tomcat
sha256:b3d5c7409cf020ea3f1ce57865e8e476e878e347963b3da02cab23b1d7464ce2
[root@mytest local]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos tomcat b3d5c7409cf0 11 seconds ago 1.263 GB
注意:运行导入的镜像的时候必须带command,否则启动报如下错误
[root@mytest ~]# docker run -d -p 8090:8088 b3d5
/usr/bin/docker-current: Error response from daemon: No command specified.
See '/usr/bin/docker-current run --help'.
动力节点在线课程涵盖零基础入门,高级进阶,在职提升三大主力内容,覆盖Java从入门到就业提升的全体系学习内容。全部Java视频教程免费观看,相关学习资料免费下载!对于火爆技术,每周一定时更新!如果想了解更多相关技术,可以到动力节点在线免费观看Docker入门视频教程哦!
代码小兵87208-09 15:04
代码小兵99203-29 17:29
杨晶珍08-02 11:09
代码小兵98808-09 14:38
代码小兵28608-09 14:50