Docker Community Forums

Share and learn in the Docker community.

Docker not seeing file modifications on bind mount

My expectation is that with a bind mount file modifications on the host machine are reflected in the container with the bind mount. This appears to not be working with docker on windows. I have not yet been able to find other reports on this issue. Can anyone shed any light on this issue?

The script below loops and cats a file repeatedly. If the file C:\work\testfile.txt is modified, I would expect the updates to show 3 seconds later with the next cat. However, this does not occur. In fact, the content of c:\work\testfile.txt seems locked in until a docker restart. It is not sufficient to run this command again.

docker run --mount type=bind,source=/,target=/mnt/external alpine sh -c "for i in 1 2 3 4 5 6 7 8 9 0 10 11 12 13 14 15 16 17 18; do sleep 3; cat /mnt/external/host_mnt/c/work/testfile.txt; done"

Version info:
Windows 10 Pro 1909 OS build 18363.720
Docker Engine v19.03.8

1 Like

For the record, I have since discovered that a “root” mount in windows seems to be problematic. For instance, the loop below does see updates to testfile.txt immediately.

docker run --mount type=bind,source=c:/work/,target=/mnt/external alpine sh -c "for i in 1 2 3 4 5 6 7 8 9 0 10 11 12 13 14 15 16 17 18; do sleep 3; cat /mnt/external/testfile1.txt; done"

We arrived at the example in my first post in analogy with a linux machine, but the better way in windows is to mount each drive letter separately if that is what you are after.

First of all while starting your container you are not using volumes but bind mounts . So you mount directory /Development/PetProjects/mindsdb on your host machine to /usr/apps/ directory. Every change made to files on your host machine in this directory, will be visible in the container, and the other way round.

If you wanted to use volumes, you could create one using docker volume create command and then running container with this volume : docker container run -v volume_name:path_in_container image_name . Then you would be able to stop container and run it again by passing this volume to run command and changes to path_in_container directory could be stored across container creations.

Another thing is that you are trying to mount /usr/apps/ in your container and you copied a python script there using Dockerfile. Note that in you current docker run command contents of /Development/PetProjects/mindsdb will replace content of /usr/apps/ in your container and if you do not have your script in /Development/PetProjects/mindsdb - script will not be visible in the container.

Moreover your CMD seems not to work because of path relativeness. You should change your CMD to CMD [ "python","/usr/apps/" ] or use WORKDIR option - WORKDIR /usr/apps/ so your python command could be executed from this directory and script could be visible there.

More information about differences between volumes and bind mounts can be found in docker documentation.