Docker Community Forums

Share and learn in the Docker community.

Sharing a single file via a volume mount does not work as expected


(Tnegeli) #1

I typically only share files and folders which I want to store in my GIT between the host and my containers.
I use volume mounts for this.
The content that is generated from the webapplication within the containers (e.g. the vendor directory generated by composer) is synced via RSYNC to my host, via a manual script.
This gives me best performance.

This way, I need a direct volume mount for the composer.json and the composer.lock file.
Both files live in my GIT and are manipulated by the PHP container if required.

If I now switch branches on my host, and the content of the composer.json or composer.lock file changes due to different content from GIT, both files in the container are broken.
They get a filesize of 0 Byte and the ownership of the file is changed to ? and ? for user and group.

I then have to restart the docker application to get everything working again.

I do not have this problem with files living inside folders that are shared via volume mounts.
There is only an issue if a volume mount is used for single file sharing.

Any suggestion to solve this issue?


(Tnegeli) #2

We have the same problem on docker for Windows. Any suggestions?


(Julien Maitrehenry) #3

Hi @tnegeli, what you see is normal. Let me explain why.
The bind-mount is based on inode on Linux. Most of the time, when we change/edit a file, the editor will create a new inode and replace the old file with the new file. In this case, the bind-mount is still on the old file and the container do not see the change.

If the change is made inplace, the inode will not change and the container will see the change.
As I know, this is a known limitation of file-mounts and we don’t have a fix for that other than mount the directory.


(Tnegeli) #4

@jmaitrehenry thank’s for your help.