I recently installed Docker for Mac and am seeing a very weird behavior where the contents of a file shown by “vi” and “head” don’t agree.
To troubleshoot a problem I was seeing when trying to update a file exposed to the container through a docker volume mount, I added an error “This is an error” to a python script. The error was not recognized until I renamed the file, reran the container (at which point I got an error for the missing file), then renamed the file back to the original name and reran the container. I think this much of the problem is related to or exactly inotify does not work when mounting volumes to docker daemons running in virtual machines · Issue #18246 · moby/moby · GitHub
As I investigated further I found a possibly related issue, though not explained by it.
I removed the “this is an error” line from the file using the host shell. From in side the container, if I executed the file and then ran “head ”. Both cases showed the file in its old state with the “this is an error” line - as expected per inotify does not work when mounting volumes to docker daemons running in virtual machines · Issue #18246 · moby/moby · GitHub.
The Odd issue is that when I ran “vi” within the container… It showed the updated file (per the host) with the line removed!!!.
I stopped the container. removed all containers. and started a new container and observed the same behavior.
from within the container executing the python script, and running “head -n ” both show the file with the line “this is an error”. However running vi from within the container show the error line removed, consistent with the host view.
I also confirmed through the VM console that “head ”, executing the file from the VM shell, and vi showed the file without the error line.
Why should “head ”, and python reading the file be different than vi from within the same container?