数据卷容器
命名的容器挂载数据卷,其他容器通过挂载这个父容器实现数据共享,挂载数据卷的容器,称之为数据卷容器
数据继承+共享传递
用法:--volumes-from <父容器>
案例:
(1)启动父容器D01,在/Data2/下新增内容
[root@aaa /]# docker run -it --name D01 yz/centos1
[root@0e4e41f8a565 /]# mkdir /Data2/d01
(2)D02,D03继承D01,分别在/Data2/下新增内容
[root@aaa /]# docker run -it --name D02 --volumes-from D01 yz/centos1
WARNING: IPv4 forwarding is disabled. Networking will not work.
[root@bc00e699cf55 /]# ls /Data2/
d01
[root@bc00e699cf55 /]# mkdir /Data2/d02
[root@aaa /]# docker run -it --name D03 --volumes-from D01 yz/centos1
WARNING: IPv4 forwarding is disabled. Networking will not work.
[root@cc4438e30b18 /]# ls /Data2/
d01 d02
[root@cc4438e30b18 /]# mkdir /Data2/d03
(3)回到D01查看/Data2/下的文件
[root@aaa /]# docker attach D01
[root@0e4e41f8a565 /]# ls /Data2/
d01 d02 d03
(4)删除D01,DO2修改后,D03能否访问
[root@0e4e41f8a565 Data2]# exit
exit
[root@aaa ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cc4438e30b18 yz/centos1 "/bin/sh -c /bin/bash" 2 hours ago Up 2 hours D03
bc00e699cf55 yz/centos1 "/bin/sh -c /bin/bash" 2 hours ago Up 2 hours D02
[root@aaa ~]# docker attach D02
[root@bc00e699cf55 /]# ls /Data2
d01 d02 d03
[root@bc00e699cf55 /]# touch /Data2/update_D02.txt #D02
[root@aaa ~]# docker attach D03
[root@cc4438e30b18 /]# ls /Data2/
d01 d02 d03 update_D02.txt
(5)删除D02,访问D03
[root@aaa ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cc4438e30b18 yz/centos1 "/bin/sh -c /bin/bash" 2 hours ago Up 2 hours D03
[root@aaa ~]# docker attach D03
[root@cc4438e30b18 /]# ls /Data2
d01 d02 d03 update_D02.txt
(6)新建D04继承D03,然后删除D03
[root@aaa ~]# docker run -it --name D04 --volumes-from D03 centos
WARNING: IPv4 forwarding is disabled. Networking will not work.
[root@96c7d644a924 /]# ls /Data2
d01 d02 d03 update_D02.txt
[root@aaa ~]# docker attach D03
[root@cc4438e30b18 /]# exit
exit
[root@aaa ~]# docker attach D04
[root@96c7d644a924 /]# ls /Data2
d01 d02 d03 update_D02.txt
结论:容器之间配置信息的传递,数据卷的生命周期一直持续到没有容器使用为止