Docker - 将容器目录暴露给主机目录而不掩盖原始内容

标签 docker mount volumes

我对 Docker 还是比较陌生,所以我还没有完全弄清楚所有的细微差别,如果这个问题已经在其他地方解决了,请原谅我。

我想在容器和主机之间共享文件。
到目前为止,我一直在使用卷,并将特定的主机目录挂载到容器目录——但这会带来一个问题,如果主机目录被弄乱了,这些更改也会出现在容器中。

我遇到的另一个问题是,如果主机目录是空的,并且挂载到容器上预先存在的目录,那么目录的内容将不可见。我知道这种行为与安装一致,所以我知道这在技术上不是问题。

但我想知道是否可以设置一个卷或替代解决方案:

  • 首先不能在主机端编辑,
  • 其次允许主机目录内容与容器目录合并

最佳答案

I wonder if it would be possible to set up a volume, or an alternative solution, that

firstly cannot be edited on the host side,

那将是一个 data volume container (with docker create on an image with a VOLUME directive)

and secondly allows for the host directory contents to be merged with the container's directory?

据我所知没有。 You would have to do some kind of copy on startup .

关于Docker - 将容器目录暴露给主机目录而不掩盖原始内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34311166/

相关文章:

mysql - Mac 上的 Docker 机器 : Cannot see mounted Volumes on docker host/docker-machine? 卷物理存储在哪里?

docker - Marathon无法运行Docker容器中的应用程序

docker - 在 ubuntu 14.04 上启动 docker 守护程序时出错(未安装设备 cgroup)

mysql - Kubernetes - NodeJs MySQL pod 无法与 MySQL pod 连接

带有 sudo 和文件路径空间的 Java exec 挂载

logging - 跨容器共享数据

node.js - Azure Linux Web 服务器没有响应我的 Docker 容器

linux - 挂载已挂载或忙

Django + Docker + SQLite3 如何将数据库挂载到容器中?

data-storage - 什么是数据量?