[英]How to create a bidirectional bind volume in Docker?
I would like to have a bidirectional volume in container.我想在容器中有一个双向卷。 I will show a basic example:
我将展示一个基本示例:
$ docker container run -d -p 80:80 -v $HOME/htdocs:/var/www/html httpd
Imagine if I extend that image and copy a content like index.html
in the /var/www/html
folder at the build process, but when I bind a empty folder $HOME/htdocs
, the content of /var/www/html
gets overwrited.想象一下,如果我在构建过程中扩展该图像并在
/var/www/html
文件夹中复制index.html
之类的内容,但是当我绑定一个空文件夹$HOME/htdocs
时, /var/www/html
的内容会得到覆盖。
Is there a way to avoid that default behaviour of overwriting of the destination of bind volume?有没有办法避免覆盖绑定卷目标的默认行为? I expect to be bidirectional, the content of
/var/www/html
should be copied to $HOME/htdocs
.我希望是双向的,
/var/www/html
的内容应该复制到$HOME/htdocs
。
The default is that if you mount a host volume the container volume gets overwritten.默认情况下,如果您挂载主机卷,则容器卷将被覆盖。
If you mount a new docker-volume the contents of the container version gets copied to the docker-volume.如果您挂载一个新的 docker-volume,容器版本的内容将被复制到 docker-volume。
If you want to have a different behavior you have to build that mechanism yourself, which is very possible, but custom如果您想拥有不同的行为,则必须自己构建该机制,这是很有可能的,但是要自定义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.