Not getting real file update in vm
I’ve been playing with docker for a while. Recently, I encountered a “bug” that I cannot identify the reason / cause.
I’m currently on windows 8.1 and have docker toolbox installed, which includes docker 1.8.2, docker-machine 0.4.1, and virtualbox 5.0.4 (these are the important ones, presumably). I used to be with pure boot2docker.
I’m not really sure about what is going on, so the description could be vague and unhelpful, please ask me for clarification if you need any. Here we go:
When I write to some files that are located in the shared folders, the vm only gets the file length update, but cannot pick up the new content.
Let’s use my app.py as an example (I’ve been playing with flask)
from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy from werkzeug.contrib.fixers import LighttpdCGIRootFix import os app = Flask(__name__) app.config.from_object(os.getenv('APP_SETTINGS')) app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app) db = SQLAlchemy(app) @app.route('/') def hello(): return "My bio!" if __name__ == '__main__': app.run(host='0.0.0.0')
and when I cat it in the vm:
Now, lets update it to the following, notice the extra exclamation marks:
from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy from werkzeug.contrib.fixers import LighttpdCGIRootFix import os app = Flask(__name__) app.config.from_object(os.getenv('APP_SETTINGS')) app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app) db = SQLAlchemy(app) @app.route('/') def hello(): return "My bio!!!!!!!" if __name__ == '__main__': app.run(host='0.0.0.0')
And when I cat it again:
Notice 2 things:
- the extra exclamation marks are not there
- the EOF sign moved, the number of the spaces, which appeared in front of the EOF sign, is exactly the number of the exclamation marks.
I suspect that the OS somehow picked up the change in file size, but failed to pick the new content. When I delete characters from the file, the EOF sign also moves, and the cat output is chopped off by exactly how many characters I deleted.
It’s not only
cat that fails to pick up the change, all programs in the vm do. Hence I cannot develop anything when it happens. The changes I make are simply not affecting anything. And I have to kill the vm and spin it up again to get any changes I make, not so efficient.
Any help will be greatly appreciated! Thank you for reading the long question!
2 Solutions collect form web for “Not getting real file update in vm”
Looks like this is a known issue.
which links to
Thanks to Matt Aitchison for replying to my github issue at gliderlabs/docker-alpine
sync; echo 3 > /proc/sys/vm/drop_caches is the temporary fix.
A permanent fix doesn’t seem to be coming any time soon…
I assume that you mounted app.py as a file, using something like
Sadly, the container will not recognize changes to a file mounted that way.
Try putting the file in a folder and mount the folder instead. Then changes to that file will be visable in the container.
Assuming app.py is located in
$(pwd)/work, try running the container with
and adjust the command being run to your code as