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

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

相关推荐
saynaihe4 小时前
ubuntu 22.04 anaconda comfyui安装
linux·运维·服务器·ubuntu
企鹅与蟒蛇4 小时前
Ubuntu-25.04 Wayland桌面环境安装Anaconda3之后无法启动anaconda-navigator问题解决
linux·运维·python·ubuntu·anaconda
小蜜蜂爱编程4 小时前
ubuntu透网方案
运维·服务器·ubuntu
AI视觉网奇5 小时前
git 访问 github
运维·开发语言·docker
G_whang5 小时前
jenkins使用Jenkinsfile部署springboot+docker项目
spring boot·docker·jenkins
头发那是一根不剩了5 小时前
nginx:SSL_CTX_use_PrivateKey failed
运维·服务器
七夜zippoe6 小时前
破解 VMware 迁移难题:跨平台迁移常见问题及自动化解决方案
运维·自动化·vmware
hweiyu007 小时前
docker简介
运维·docker·容器
Sally璐璐7 小时前
OpenVPN:深度解析开源 VPN 解决方案
运维·开源
阿巴~阿巴~8 小时前
理解Linux文件系统:从物理存储到统一接口
linux·运维·服务器