挂载码头主机卷,但覆盖容器的内容 [英] Mount docker host volume but overwrite with container's contents

查看:160
本文介绍了挂载码头主机卷,但覆盖容器的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多篇文章对Docker的音量和数据管理的理解非常有帮助。这两个特别优秀:





但是,我不知道我正在寻找什么是讨论。这是我的理解:


  1. 运行 docker运行-v / host / something:/ container / something 主机文件将重叠(但不覆盖)指定位置的容器文件。容器将无法再访问该位置的以前的文件,而只能访问该位置的主机文件。

  2. 在Dockerfile中定义卷时,其他容器可能共享内容由图像/容器创建。

  3. 主机还可以查看/修改Dockerfile卷,但只有在使用 docker inspect 发现真实的安装点之后。 (通常位于 / var / lib / docker / vfs / dir / cde167197ccc3e138a14f1a4f7c .... 之类的地方)。然而,当Docker必须在Virtualbox VM中运行时,这是毛茸茸的。

我的问题很简单。如何反转叠加层,以便在安装卷时,容器文件优先于我的主机文件?



我想指定一个挂载点,我可以轻松访问容器文件系统。但是似乎没有人问这个问题。我明白我可以使用数据容器,或者我可以使用docker检查找到mountpoint,但是在这种情况下,这两种解决方案都不是一个很好的解决方案。

解决方案

Docker 1.10+共享文件的方式是通过一个卷,如 docker volume create

这意味着,您不需要专用于数据卷的容器,您可以直接使用数据卷。



这样,您可以在容器中共享并装载该卷,然后将其内容保留在所述卷中。

这更符合容器的工作原理:从主机中隔离内存,cpu和文件系统:这就是为什么你不能装载卷并且容器的文件优先于主机文件:将破坏该容器隔离并向主机公开其内容。


Several articles have been extremely helpful in understanding Docker's volume and data management. These two in particular are excellent:

However, I am not sure if what I am looking for is discussed. Here is my understanding:

  1. When running docker run -v /host/something:/container/something the host files will overlay (but not overwrite) the container files at the specified location. The container will no longer have access to the location's previous files, but instead only have access to the host files at that location.
  2. When defining a volume in Dockerfile, other containers may share the contents created by the image/container.
  3. The host may also view/modify a Dockerfile volume, but only after discovering the true mountpoint using docker inspect. (usually somewhere like /var/lib/docker/vfs/dir/cde167197ccc3e138a14f1a4f7c....). However, this is hairy when Docker has to run inside a Virtualbox VM.

My question is simple. How can I reverse the overlay so that when mounting a volume, the container files take precedence over my host files?

I want to specify a mountpoint where I can easily access the container filesystem. But there just doesn't seem to be anyone asking this question. I understand I can use a data container for this, or I can use docker inspect to find the mountpoint, but neither solution is a good solution in this case.

解决方案

The docker 1.10+ way of sharing files would be through a volume, as in docker volume create.
That means, you don't need a container dedicated to a data volume, you can use a data volume directly.

That way, you can share and mount that volume in a container which will then keep its content in said volume.
That is more in line with how a container is working: isolating memory, cpu and filesystem from the host: that is why you cannot "mount a volume and have the container's files take precedence over the host file": that would break that container isolation and expose to the host its content.

这篇关于挂载码头主机卷,但覆盖容器的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆