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数据依然共享

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

相关推荐
无奈笑天下18 分钟前
银河麒麟高级服务器操作系统【配置 sudo 操作日志记录】操作方法
linux·运维·服务器
Android系统攻城狮28 分钟前
FFmpeg深度解析之av_codec_iterate:如何遍历音视频编解码器?(七十八)
linux·运维·ffmpeg·音视频·1024程序员节·音视频进阶
AR-26710-43 分钟前
docker Day5——改动+systemf复习
运维·docker·容器
jipinxiaofeihua2 小时前
(文章6) 03章-C++文件操作(下)
linux·运维·网络
饿了吃洗衣凝珠12 小时前
shell
linux·运维·服务器
Decay__14 小时前
PostgreSQL 性能调优方法论 —— pg_stat_statements、EXPLAIN ANALYZE、瓶颈定位流程与参数基线
运维·数据库·sql·postgresql
always202216 小时前
AI运行时 · 06 - Kata 与 K8s 集成:RuntimeClass / CSI kata-directvolume / 性能开销与调优
人工智能·容器·kubernetes
stormsha19 小时前
中文路径让 MySQL 起不来:Failed to find valid data directory 与 Illegal byte sequence
运维·数据库·mysql
stormsha19 小时前
MySQL 报 `data directory has files in it`:初始化失败一次,之后就永久起不来
运维·数据库·mysql
csdn_aspnet21 小时前
使用 Docker 配置 PostgreSQL 和 pgAdmin 4
数据库·docker·postgresql·pgadmin4