3

I mount a host file into a docker container, and the mounted file becomes a directory inside the container. 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.

The source code is added into /code during build. The corresponding line in my Dockerfile is:

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?

3
  • Weird. Looks like a bug tbh. Commented Nov 6, 2015 at 13:01
  • @AdrianMouat your comment gave me an idea to report it as a bug. While preparing a bug report, I tried to replicate it in some minimal example, and figured out what went wrong. Thank you :) Commented Nov 6, 2015 at 14:02
  • Interesting, I didn't actually know it would do that if the directory doesn't exist on the host. Not sure I was much help, but I'm glad you got it sorted. Commented Nov 6, 2015 at 14:29

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to be able to modify a file on the host machine and have changes reflect within a container, you should mount the volume via -v HOST_PATH:CONTAINER_PATH when you run the container.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.