zoukankan      html  css  js  c++  java
  • docker系列之六容器数据卷

    docker之容器数据卷

    一.容器数据卷

      docker容器运行的时候,会产生一系列的文件,那么我们希望容器产生的数据能提供给其他的容器使用,也就是说怎么实现容器间的数据的共享呢?这就需要用到我们所提到的容器数据卷。

    二.如何实现容器数据卷

      实现容器数据卷的方式非常的简单,首先我们需要创建一个容器,然后其他的容器使用 --volumes-from 命令挂载到这个容器(父容器)。具体的流程如下:

      a.我们根据上一节创建的镜像mycentos:me,来启动一个容器,名字叫doc1,命令为:docker run -it --name doc1 mycentos:me

                                                         

          b.再启动一个容器,名字叫doc2,继承doc1,命令为:docker run -it --name doc2 --volumes-from doc1 mycentos:me            

                                                         

           c.在doc1的 /containerDataVolumn/ 目录下新建一个文件,并向添加内容,如下图所示: 

                                                         

         进入doc2容器的 /containerDataVolumn/ 目录,查看文件,并查看器内容,如下图所示: 

                                                        

       d.在doc2容器的/containerDataVolumn目录下添加文件doc2_add.txt,然后在doc1容器对应的目录下,会发现与c步骤一致。

      e.然后启动一个新的容器名字叫doc3, 进入到doc3的/containerDataVolumn目录下,会看到有doc1_add.txt和doc2_add.txt文件,如下图所示:

                                                         

       f.在doc3的数据卷中添加doc3_add.txt文件,在doc1和doc2容器中均能看到。

      g.将doc1容器删除,在doc2或者doc3中添加文件,他们之间的数据依然是可见的。

  • 相关阅读:
    【leetcode】106. Construct Binary Tree from Inorder and Postorder Traversal
    【leetcode】105. Construct Binary Tree from Preorder and Inorder Traversal
    【leetcode】236. Lowest Common Ancestor of a Binary Tree
    【leetcode】235. Lowest Common Ancestor of a Binary Search Tree
    【leetcode】352. Data Stream as Disjoint Intervals
    【leetcode】897. Increasing Order Search Tree
    【leetcode】900. RLE Iterator
    BEC listen and translation exercise 26
    BEC listen and translation exercise 25
    BEC listen and translation exercise 24
  • 原文地址:https://www.cnblogs.com/miller-zou/p/11110322.html
Copyright © 2011-2022 走看看