Tracking folder on host machine to use in container

Is it possible to track live changes on a folder path in the host system to update data in the container without needing to restart the container. I am currently using a host mounted volume, but if data is updated in the file, it will not update inside the container unless it is restarted. My docker-compose file grabs data from the host-folder and puts it in the container-folder.

My docker-compose file -

version: "3.9"
    build: ./ExpressBackend
      - type: bind
        source: C:/Users/host-folder
        target: /usr/src/app/container-folder

Can you please format your compose file content according this instructions:

This would’ve worked fine with docker-ce on Linux. As I can’t say how the behavior or Docker Desktop for Windows is, I have to leave this one for someone else to respond.

It should work on Windows too. Are you sure you mounted the right folder and you are checking the file in the container in the right folder? Is it a file that your user can access? I am asking it because your source path is an absolute path pointing to a folder under “Users”

Yes, it is the correct path. I have noticed that it does work on Linux based on how I edit it. If I edit it with a gui, it doesn’t work. When I use the “nano” command to edit documents on linux, it did work. I used the windows notepad to edit a txt file and it didn’t work.

Interesting. Based on your example compose file I assumed you mount a whole folder, but in that case it should not matter how you edit a file in that folder. Because of my assumtion I didn’t mention what you found out, but when you mount only a file on Linux, Docker will use the inode behind the filename to mount, so when you use an editor which creates a copy of the file, changes it, removes the original file and rename the copy to the same name as the original, already deleted file had, the inode is still there on the filesystem, but your host does not have a reference to it, only inside the container. Your new file will just have the same name, but it will be a physically different file, not mounted to the container.

I don’t know what happens when you mount a file from your Windows host instead of a Linux host, but if there is something similar to what I described and you actually mounted a file, not a folder, you can edit that file only with an editor that change the file directly without using any copying and replacing.

I am mounting a whole folder. I am just using a txt document inside as a test for making changes to the folder.

Then I don’t know why it doesn’t work. I mounted a folder, changed the file with notepad on Windows and it changed in the container too.