Docker数据卷容器(容器继承)

Docker数据卷容器(容器继承)

命名的容器挂载数据卷。其他容器通过挂载这个容器实现数据共享,挂载数据的容器 -> 称之为数据卷容器

创建DockerFile

shell 复制代码
FROM centos

VOLUME ["dataVolume01", "dataVolume02"]

CMD /bin/bash

构建镜像

shell 复制代码
docker build -f dockerFile02 -t mzw/centos .

启动容器

启动容器并命名为test01

shell 复制代码
docker run -it --name test01 mzw/centos

修改数据卷

进入数据卷

shell 复制代码
cd dataVolume01

创建文件并填写数据

shell 复制代码
echo hello >> a.txt

创建子容器

创建子容器,命名为test02,指定数据卷为容器test01

shell 复制代码
docker run -it --name test02 --volumes-from test01 mzw/centos

创建子容器,命名为test03,指定数据卷为容器test01

shell 复制代码
docker run -it --name test03 --volumes-from test01 mzw/centos

验证

  • 在容器test02中进入数据卷

    shell 复制代码
    cd dataVolume01
  • 查看内部数据

    shell 复制代码
    cat a.txt 


    test02与test01 数据卷内容一致

  • 修改test02内数据卷内容,查看test01内数据卷

    • 修改test02数据卷内容
    • 查看test01数据内容

      test01与test02 数据卷内容一致

此时删掉test01容器,02和03数据依然共享

数据卷的生命周期一直持续到没有容器使用为止

相关推荐
dessler26 分钟前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
少妇的美梦19 小时前
logstash教程
运维
容器魔方19 小时前
Bloomberg 正式加入 Karmada 用户组!
云原生·容器·云计算
chen94519 小时前
k8s集群部署vector日志采集器
运维
chen94519 小时前
aws ec2部署harbor,使用s3存储
运维
muyun28001 天前
Docker 下部署 Elasticsearch 8 并集成 Kibana 和 IK 分词器
elasticsearch·docker·容器
東雪蓮☆1 天前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
qq_264220891 天前
LVS负载均衡群集和LVS+Keepalived群集
运维·负载均衡·lvs
乌萨奇也要立志学C++1 天前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
雨落Liy1 天前
Nginx 从入门到进阶:反向代理、负载均衡与高性能实战指南
运维·nginx·负载均衡