简体   繁体   English

如何在不使用Docker主机安装主机的情况下共享特定文件?

[英]How to share a specific file without host mounting with Docker?

I have a container from which I want to expose files to another container without using host mounting. 我有一个容器,我想从中将文件公开到另一个容器而不使用主机安装。

In my Dockerfile I declared the /etc/nginx/ directory as a volume after I copied the necessary files: 在复制必要的文件后,我在Dockerfile中将/etc/nginx/目录声明为卷:

COPY ./src/frontend/config/nginx.conf /etc/nginx/nginx.conf
COPY ./src/frontend/config/sites-available/default /etc/nginx/sites-enabled/default
VOLUME ["/etc/nginx/"]

But because the whole directory acts as a volume the original contents of /etc/nginx/ is shadowed by the contents of my volume: 但是因为整个目录都充当一个卷,所以/etc/nginx/的原始内容被我的卷的内容所遮盖:

dk run --volumes-from other_container -it --rm nginx:1.12.1 /bin/bash
> ls /etc/nginx
> nginx.conf sites-enabled

This is something which I'd like to avoid. 这是我要避免的事情。 However it seems that Docker doesn't really support exposing an existing file as a volume. 但是,似乎Docker并不真正支持将现有文件作为卷公开。

VOLUME ["/etc/nginx/nginx.conf"]

If I use the volume as above I get the following error message: 如果我按上述方式使用该卷,则会收到以下错误消息:

cannot mount volume over existing file, file exists /var/lib/docker/overlay2/b557a0d1ef5026f581f7ee69321de854d8f77b935c0442458f26cada855e5bf2/merged/etc/nginx/nginx.conf

Is it possible to solve this problem without using host mounting? 不使用主机安装就可以解决此问题吗?

When Docker volumes are mounted, they hide any previous content on the mountpoint. 挂载Docker卷时,它们会将所有先前的内容隐藏在挂载点上。

For this reason, the volume has to be mounted in a separate directory, for instance /etc/nginx/extra/ or anywhere else. 因此,必须将卷挂载在单独的目录中,例如/ etc / nginx / extra /或其他任何位置。 All other config files need to be adapted in order to make the includes from the right directory. 需要修改所有其他配置文件,以便从正确的目录进行包含。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM