简体   繁体   English

挂载的主机文件成为 docker 容器内的目录

[英]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.

相关问题 在Windows主机上的docker容器内的已安装文件夹中更改文件权限 - Change file permissions in mounted folder inside docker container on Windows Host Tomcat Docker容器:作为容器webapp目录挂载的主机webapp目录 - Tomcat Docker Container: host webapp directory mounted as container webapp directory Docker - 安装目录在容器内为空 - Docker - mounted directory is empty inside container 允许 Docker 容器和主机用户写入绑定挂载的主机目录 - Allow Docker Container & Host User To Write on Bind Mounted Host Directory docker挂载主机目录文件权限 - docker mounted host directory file permissions 如何将文件复制到Docker容器中的主机安装目录 - How to copy files to host-mounted directory in docker container Docker - 检查容器内的目录是否从主机挂载 - Docker - check within the container if a directory is mounted from the host or not 在Docker中,如何从容器内部检测Docker是否挂载了文件或目录? - In Docker, how do I detect from inside a container, that if a file or a directory is mounted by the Docker? 在容器 1 内运行的 Docker 应用程序如何从容器 2 读取文件,容器 2 是卷安装到主机的 - How does Docker App Running Inside Container 1 should read file from Container 2 which is Volume Mounted to Host Machine GitLab 和 Docker Compose:容器内的挂载目录为空 - GitLab and Docker Compose: Mounted directory is empty inside container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM