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?