zoukankan      html  css  js  c++  java
  • docker容器跨服务器的迁移

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

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

    export

    找出要备份容器的ID

    [root@wls12c ~]$ docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   NAMES
    037b847bf093        centos              "/bin/bash"         3 minutes ago       Exited (0) 2 minute      naughty_davinci     

    备份

    [root@wls12c ~]$ docker export 037b847bf093 >centos_demo.tar
    [root@wls12c ~]$ du -sh centos_demo.tar 
    195M    centos_demo.tar

    export是把容器打成一个tar包。

    恢复

    把刚才备份的centos_demo.tar打包到目标服务器

    [root@11g ~]$ cat centos_demo.tar |docker import - centos:demo
    8962416d1362f289ceb9848e21a95f03dc34eb6f234c8f98f1a6e1ec7fe34a67


    查看新生成的镜像

    [root@11g ~]$ docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    centos              demo                8962416d1362        24 seconds ago      196.7 MB

    save

    得到镜像名称

    [root@wls12c ~]$ docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    centos              latest              d83a55af4e75        3 weeks ago         196.7 MB

    备份镜像

    [root@wls12c ~]$ docker save centos >centos_save.tar

    恢复镜像

    [root@11g ~]$ docker load <centos_save.tar 

    查看恢复的镜像

    [root@wls12c ~]$ docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             
    centos              latest              d83a55af4e75        3 weeks ago         196.7 MB

    两者的区别:

    导出后再导入(exported-imported)的镜像会丢失所有的历史,而保存后再加载(saveed-loaded)的镜像没有丢失历史和层 (layer)。这意味着使用导出后再导入的方式,你将无法回滚到之前的层(layer),同时,使用保存后再加载的方式持久化整个镜像,就可以做到层回 滚(可以执行docker tag <LAYER ID> <IMAGE NAME>来回滚之前的层)。

  • 相关阅读:
    关于用网线连开发板和电脑网卡问题
    信号量同步编程
    信号量互斥编程
    信号通讯
    有名管道通讯
    dell 燃 7000 系列 7460/7560 禁用触控板 触摸板
    关于错误node_modules/@types/jasmine/index.d.ts(39,52): error TS1005: '=' expected.
    环境配置,nodejs,cnpm,git,webstorm,powershell,
    gitflow工作流
    <问题汇总>ionic2开发app
  • 原文地址:https://www.cnblogs.com/zydev/p/5800543.html
Copyright © 2011-2022 走看看