• 3. 容器备份与迁移


    
    

    [root@VM_0_3_centos ~]# docker ps -a // 查看本地的容器
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    dc92bf4f2dab redis:latest "docker-entrypoint..." 49 minutes ago Exited (0) 40 minutes ago myredis
    f9941aca500b nginx:latest "nginx -g 'daemon ..." 15 hours ago Exited (0) 4 seconds ago nginx
    a8168338d283 tomcat:7-jre8 "catalina.sh run" 15 hours ago Up About an hour 0.0.0.0:8080->8080/tcp tomcat
    750f40204378 centos:latest "/bin/bash" 4 days ago Exited (137) 14 hours ago mycentos
    [root@VM_0_3_centos ~]# docker images // 查看本地的镜像
    REPOSITORY TAG IMAGE ID CREATED SIZE
    docker.io/centos latest 75835a67d134 8 days ago 200 MB
    docker.io/nginx latest be1f31be9a87 2 weeks ago 109 MB
    docker.io/redis latest 0a153379a539 2 weeks ago 83.4 MB
    docker.io/solr latest 45749c8baa2a 2 weeks ago 834 MB
    docker.io/tomcat 7-jre8 82af61923130 3 weeks ago 463 MB
    docker.io/zookeeper latest 89f7884dcc4e 3 weeks ago 148 MB
    docker.io/mysql 5.6 1f47fade220d 6 weeks ago 256 MB
    【 1. 容器保存为镜像 把nginx容器备份为wuleinginx镜像 】
    [root@VM_0_3_centos ~]# docker commit nginx wuleinginx
    sha256:7856283560cbb2f04afff3a619b1ce52d212dad41b3c3aa0e4471ab7382bb674
    [root@VM_0_3_centos ~]# docker images // 可以看到我们新建的镜像成功了
    REPOSITORY TAG IMAGE ID CREATED SIZE
    wuleinginx latest 7856283560cb 9 seconds ago 109 MB
    docker.io/centos latest 75835a67d134 8 days ago 200 MB
    docker.io/nginx latest be1f31be9a87 2 weeks ago 109 MB
    docker.io/redis latest 0a153379a539 2 weeks ago 83.4 MB
    docker.io/solr latest 45749c8baa2a 2 weeks ago 834 MB
    docker.io/tomcat 7-jre8 82af61923130 3 weeks ago 463 MB
    docker.io/zookeeper latest 89f7884dcc4e 3 weeks ago 148 MB
    docker.io/mysql 5.6 1f47fade220d 6 weeks ago 256 MB
    【 2. 镜像备份 把镜像以文件形式保存到宿主机 】
    [root@VM_0_3_centos ~]# docker save -o /wuleinginx.tar wuleinginx
    [root@VM_0_3_centos ~]# cd / && ll
    total 110388
    drwxr-xr-x 3 root root 4096 Oct 17 19:28 app
    lrwxrwxrwx. 1 root root 7 Jun 11 2017 bin -> usr/bin
    dr-xr-xr-x. 4 root root 4096 Apr 12 2018 boot
    drwxr-xr-x 2 root root 4096 Apr 12 2018 data
    drwxr-xr-x 19 root root 2980 Oct 18 09:41 dev
    drwxr-xr-x. 91 root root 12288 Oct 18 09:41 etc
    drwxr-xr-x. 2 root root 4096 Sep 29 15:19 home
    -rwxr-xr-x 1 root root 4 Oct 18 09:41 idus.log
    lrwxrwxrwx. 1 root root 7 Jun 11 2017 lib -> usr/lib
    lrwxrwxrwx. 1 root root 9 Jun 11 2017 lib64 -> usr/lib64
    drwx------. 2 root root 16384 Jun 11 2017 lost+found
    drwxr-xr-x. 2 root root 4096 Nov 5 2016 media
    drwxr-xr-x. 3 root root 4096 Oct 18 05:31 mnt
    -rw-r--r-- 1 root root 982 Oct 17 19:45 nginx.conf
    drwxr-xr-x. 3 root root 4096 Jun 11 2017 opt
    dr-xr-xr-x 105 root root 0 Oct 18 09:41 proc
    dr-xr-x---. 9 root root 4096 Oct 18 05:31 root
    drwxr-xr-x 26 root root 900 Oct 18 09:43 run
    lrwxrwxrwx. 1 root root 8 Jun 11 2017 sbin -> usr/sbin
    drwxr-xr-x. 2 root root 4096 Nov 5 2016 srv
    dr-xr-xr-x 13 root root 0 Oct 18 09:41 sys
    drwxrwxrwt. 77 root root 4096 Oct 18 09:42 tmp
    drwxr-xr-x. 13 root root 4096 Jun 11 2017 usr
    drwxr-xr-x. 20 root root 4096 Oct 18 09:41 var
    -rwxr-xr-x 1 root root 4 Oct 18 09:41 vga.conf
    -rw-r--r-- 1 root root 2861 Oct 5 12:42 wget-log
    -rw------- 1 root root 112824832 Oct 18 10:52 wuleinginx.tar
    【 3. 镜像恢复 】
    // 先把本地相关的容器和镜像删掉
    [root@VM_0_3_centos /]# docker rmi wuleinginx
    Untagged: wuleinginx:latest
    Deleted: sha256:7856283560cbb2f04afff3a619b1ce52d212dad41b3c3aa0e4471ab7382bb674
    Deleted: sha256:bae433800e271454887fd71749800b7834be47a7d0b4be5a69f643a7dcba64f1
    [root@VM_0_3_centos /]# docker rm nginx
    nginx
    [root@VM_0_3_centos /]# docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    dc92bf4f2dab redis:latest "docker-entrypoint..." 58 minutes ago Exited (0) 49 minutes ago myredis
    a8168338d283 tomcat:7-jre8 "catalina.sh run" 16 hours ago Up About an hour 0.0.0.0:8080->8080/tcp tomcat
    750f40204378 centos:latest "/bin/bash" 4 days ago Exited (137) 14 hours ago mycentos
    [root@VM_0_3_centos /]# docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    docker.io/centos latest 75835a67d134 8 days ago 200 MB
    docker.io/nginx latest be1f31be9a87 2 weeks ago 109 MB
    docker.io/redis latest 0a153379a539 2 weeks ago 83.4 MB
    docker.io/solr latest 45749c8baa2a 2 weeks ago 834 MB
    docker.io/tomcat 7-jre8 82af61923130 3 weeks ago 463 MB
    docker.io/zookeeper latest 89f7884dcc4e 3 weeks ago 148 MB
    docker.io/mysql 5.6 1f47fade220d 6 weeks ago 256 MB
    // 开始备份
    root@VM_0_3_centos /]# docker load -i /wuleinginx.tar
    a8f3695862a0: Loading layer [==================================================>] 11.26 kB/11.26 kB
    Loaded image: wuleinginx:latest
    [root@VM_0_3_centos /]# docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    wuleinginx latest 7856283560cb 14 minutes ago 109 MB
    docker.io/centos latest 75835a67d134 8 days ago 200 MB
    docker.io/nginx latest be1f31be9a87 2 weeks ago 109 MB
    docker.io/redis latest 0a153379a539 2 weeks ago 83.4 MB
    docker.io/solr latest 45749c8baa2a 2 weeks ago 834 MB
    docker.io/tomcat 7-jre8 82af61923130 3 weeks ago 463 MB
    docker.io/zookeeper latest 89f7884dcc4e 3 weeks ago 148 MB
    docker.io/mysql 5.6 1f47fade220d 6 weeks ago 256 MB
    【 4. 部署容器 】
    [root@VM_0_3_centos /]# docker run -id --name=wuleinginx -p 80:80 wuleinginx:latest
    14a8c8b3bf374216a3403869c4002c55b3185458a337d16ebd7b29f34c513b17
    [root@VM_0_3_centos /]# docker ps -a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    14a8c8b3bf37 wuleinginx:latest "nginx -g 'daemon ..." 4 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp wuleinginx
    dc92bf4f2dab redis:latest "docker-entrypoint..." About an hour ago Exited (0) 57 minutes ago myredis
    a8168338d283 tomcat:7-jre8 "catalina.sh run" 16 hours ago Up About an hour 0.0.0.0:8080->8080/tcp tomcat
    750f40204378 centos:latest "/bin/bash" 4 days ago Exited (137) 15 hours ago mycentos
    [root@VM_0_3_centos /]#

    测试:

        

  • 相关阅读:
    初学flask
    第一次使用pyqt5解决的几个小问题
    一些细节
    关于random
    go语言 方法
    go 语言 struct 另类构造函数 继承
    go 语言 链表 的增删改查
    go 语言 链表
    go 语言struct
    无题
  • 原文地址:https://www.cnblogs.com/wlwl/p/9809410.html
Copyright © 2020-2023  润新知