Volumes mapped as specific files have different behaviour to volumes mapped as individual files
There is something strange going on with updating file that are mapped from a local machine into a docker container.
Given the following directory structure:
vagrant@carverlinux ~/docker-compose-poc [127]> tree
.
├── data
│ └── myfile.txt
└── docker-compose.yaml
and the following docker-compose file:
---
version: "3.8"
services:
demo:
image: ubuntu
volumes:
- ./data/myfile.txt:/demo/myfile.txt
- ./data:/demo/data
If you update myfile.txt to have a different value while the container is running for some reason the version that is mapped in via a directory ./demo/data/myfile.txt updates but the version that is mapped as an invididual file ./demo/myfile.txt does not - requiring the container to be restarted in order to pick up the change:
Output below:
docker-compose run demo bash
root@d60316398406:/# cat /demo/myfile.txt
hello world
root@d60316398406:/# cat /demo/data/myfile.txt
hello world
root@d60316398406:/# cat /demo/myfile.txt
hello world
root@d60316398406:/# cat /demo/data/myfile.txt
hello world
i've changed it
Anybody know why this behaviour is occuring and how to fix it?
@jamesla
Thanks for reporting issue, however I was not able to replicate on my ends, mind to share docker info output ? Are you using the last version ?
I used exactly the same compose file as you did, but updating the file while container is running give me the expected output
root@1bb9e71035c2:/# cat demo/myfile.txt demo/data/myfile.txt
HelloWorld!
HelloWorld!
#####################################################
# Update content of data/myfile.txt from host side #
#####################################################
root@1bb9e71035c2:/# cat demo/myfile.txt demo/data/myfile.txt
ByeWorld!
ByeWorld!
Hey this randomly started working again thanks for your help :-)