本文共 3272 字,大约阅读时间需要 10 分钟。
Docker的备份方式有export和save两种。
export是当前的状态,针对的是容器,docker save 是针对镜像images。
[root@mytest2 local]# docker images REPOSITORY TAG IMAGE ID CREATED SIZEshiyu/centos tomcat-centos b61b207a5809 28 minutes ago 1.263 GBdocker.io/centos latest 2d194b392dd1 7 hours ago 195.4 MBdocker.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 imagesREPOSITORY TAG IMAGE ID CREATED SIZE[root@mytest local]# docker load < mytomcat.tarb03095563b79: Loading layer [==================================================>] 204 MB/204 MB1d88d689ca13: Loading layer [==================================================>] 3.584 kB/3.584 kBa997e4440673: Loading layer [==================================================>] 2.56 kB/2.56 kB0a3b6c7be500: Loading layer [==================================================>] 309.5 MB/309.5 MBcee5bf38dfe0: Loading layer [==================================================>] 774.1 MB/774.1 MBLoaded image ID: sha256:b61b207a5809e56150df90e9c419f838c9a0988828773ef33aa2768e589c19c2kB/774.1 MB[root@mytest local]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEb61b207a5809 About an hour ago 1.263 GB[root@mytest local]# docker tag b61b mytomcat:2.0[root@mytest local]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmytomcat 2.0 b61b207a5809 About an hour ago 1.263 G
[root@mytest2 local]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8578122af714 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 imagesREPOSITORY TAG IMAGE ID CREATED SIZE[root@mytest local]# cat mytomcat_export.tar |docker import - centos:tomcatsha256:b3d5c7409cf020ea3f1ce57865e8e476e878e347963b3da02cab23b1d7464ce2[root@mytest local]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos 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'.
转载地址:http://tdhji.baihongyu.com/