Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 306
t_tia Avatar asked Dec 03 '25 09:12

t_tia


1 Answers

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.

like image 172
t_tia Avatar answered Dec 05 '25 14:12

t_tia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!