[英]Mounted host file becomes a directory inside a docker container
I mount a host file into a docker container, and the mounted file becomes a directory inside the container.我将主机文件挂载到 docker 容器中,挂载的文件成为容器内的目录。 That's how I run it:这就是我运行它的方式:
$ docker run --name <containername> -it -d -v /home/core/account_config.py:/code/account_config.py <imagename>
Inside the container:容器内部:
# ls -la
-rw-r--r--. 4 root root 0 Nov 6 10:25 __init__.py
drwxr-xr-x. 2 root root 4096 Nov 6 10:59 account_config.py
....
The file (in the host file system) is still a perfectly ok python file.该文件(在主机文件系统中)仍然是一个完美的 python 文件。
The source code is added into /code
during build.源代码在构建期间添加到/code
中。 The corresponding line in my Dockerfile is:我的 Dockerfile 中的相应行是:
ADD ./code /code
I want to be able to change the content of config file without rebuilding the image, so I want mount it later.我希望能够在不重建映像的情况下更改配置文件的内容,所以我想稍后安装它。 What went wrong and how can I fix this?出了什么问题,我该如何解决?
As it happens with (almost) every weird issue, turned out that this one has a very simple solution.正如(几乎)所有奇怪的问题所发生的那样,事实证明这个问题有一个非常简单的解决方案。
The path to host file contained a typo, so the docker automatically created a directory in this path, and mounted it to the container.主机文件的路径包含拼写错误,因此 docker 会自动在此路径中创建一个目录,并将其挂载到容器中。
如果您希望能够修改主机上的文件并使更改反映在容器中,则应在run
-v HOST_PATH:CONTAINER_PATH
时通过-v HOST_PATH:CONTAINER_PATH
挂载卷。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.