docker夸服务器迁移

Docker跨服务器迁移

2018年03月06日 17:34:45

Docker的备份方式有export和save两种。

export是当前的状态,针对的是容器,docker save 是针对镜像images。

一、镜像的迁移—save

1.镜像保存

登陆到已经部署好镜像的服务器上面,执行以下命令进行导出

  1. [root@mytest2 local]# docker images

  2. REPOSITORY TAG IMAGE ID CREATED SIZE

  3. shiyu/centos tomcat-centos b61b207a5809 28 minutes ago 1.263 GB

  4. docker.io/centos latest 2d194b392dd1 7 hours ago 195.4 MB

  5. docker.io/centos 7.3.1611 66ee80d59a68 4 months ago 191.8 MB

  6. [root@mytest2 local]# docker save b61b >mytomcat.tar

2.将镜像导入

将刚才导出的镜像上传到你要导入的那台服务器上

  1. [root@mytest local]# scp  mytomcat.tar 192.168.0.4:/usr/local/

  2. [email protected]'s password:

  3. mytomcat.tar                                                                                                100% 1228MB  49.1MB/s   00:25

执行以下命令镜像导入

  1. [root@mytest local]# ll mytomcat.tar

  2. -rw-r--r-- 1 root root 1287580160 Mar  6 16:36 mytomcat.tar

  3. [root@mytest local]# docker images

  4. REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

  5. [root@mytest local]# docker load < mytomcat.tar

  6. b03095563b79: Loading layer [==================================================>]   204 MB/204 MB

  7. 1d88d689ca13: Loading layer [==================================================>] 3.584 kB/3.584 kB

  8. a997e4440673: Loading layer [==================================================>]  2.56 kB/2.56 kB

  9. 0a3b6c7be500: Loading layer [==================================================>] 309.5 MB/309.5 MB

  10. cee5bf38dfe0: Loading layer [==================================================>] 774.1 MB/774.1 MB

  11. Loaded image ID: sha256:b61b207a5809e56150df90e9c419f838c9a0988828773ef33aa2768e589c19c2kB/774.1 MB

  12. [root@mytest local]# docker images

  13. REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

  14. <none>              <none>              b61b207a5809        About an hour ago   1.263 GB

  15. [root@mytest local]# docker tag b61b mytomcat:2.0

  16. [root@mytest local]# docker images

  17. REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

  18. mytomcat            2.0                 b61b207a5809        About an hour ago   1.263 G


二、容器的迁移—export

1.导出容器

 
  1. [root@mytest2 local]# docker ps -a

  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

  3. 8578122af714 b61b "/bin/sh -c '/usr/loc" 56 minutes ago Up 56 minutes 0.0.0.0:8090->8088/tcp naughty_bartik

  4. [root@mytest2 local]# docker export 8578122af714 > mytomcat_export.tar

2.导入到新的服务器上

同样需要将刚才的导出的容器备份上传到目标服务器上,执行下面的命令

 
  1. [root@mytest local]# docker images

  2. REPOSITORY TAG IMAGE ID CREATED SIZE

  3. [root@mytest local]# cat mytomcat_export.tar |docker import - centos:tomcat

  4. sha256:b3d5c7409cf020ea3f1ce57865e8e476e878e347963b3da02cab23b1d7464ce2

  5. [root@mytest local]# docker images

  6. REPOSITORY TAG IMAGE ID CREATED SIZE

  7. centos tomcat b3d5c7409cf0 11 seconds ago 1.263 GB

注意:运行导入的镜像的时候必须带command,否则启动报如下错误

 
  1. [root@mytest ~]# docker run -d -p 8090:8088 b3d5

  2. /usr/bin/docker-current: Error response from daemon: No command specified.

  3. See '/usr/bin/docker-current run --help'.

猜你喜欢

转载自blog.csdn.net/m18994118189/article/details/81942748