问题
I run docker on windows 10 with this command:
docker run -d -v /c/Users/tsh/docker:/usr/share/nginx/html -p 80:80 nginx
Inside Users/tsh/docker folder I have simple index.html file:
<h1>Hello!</h1>
It works perfectly well, when I point my browser on windows to virtualbox IP I can see web page with "Hello!" displayed. But when I change content of the index.html to something like:
<h1>Hello from docker!</h1>
The web page still shows me the old "Hello!" text.
Is it possible when I change index.html data on the web page is also changed?
Upd:
docker run -it -v //c/Users/tsh/docker:/usr/share/nginx/html -p 80:80 nginx bash
root@ae5fc6b6126a:/# cd /usr/share/nginx/html
root@ae5fc6b6126a:/usr/share/nginx/html# cat index.html
<h1>Hello from docker!</h1>
root@ae5fc6b6126a:/usr/share/nginx/html#
Container see new data <h1>Hello from docker!</h1>
but page still shows the old Hello!
回答1:
This problem appears to be related to Virtualbox caching. I also encountered this problem recently editing CSS and I was able to create a "workaround" by resetting the image in Virtualbox. But, I call this a workaround only in a vague sense since it is not very useful to have to completely reboot the boot2docker image each time you make an edit to an HTML doc.
回答2:
There seems to be some issues with the windows paths. Please try the workaround suggested in Github issue https://github.com/docker/docker/issues/12590
Use double leading slashes on the path:
docker run -d -v --name mynginx //c/Users/tsh/docker:/usr/share/nginx/html -p 80:80 nginx
You can debug your situation as follows: First name your container as 'mynginx' using the above updated run command
Then you can enter into the container using following command:
docker exec -it mynginx /bin/bash
Now you should be inside the container, and there you can verify the contents of the mounted file using:
cat /usr/share/nginx/html/index.html
If the file here is showing your changes, and still your browser is showing the old file, that means the file is cached somewhere in the chain. Nginx / browser. If it is cached in the browser, you can check by opening in the incognito window or doing Ctrl + F5.
回答3:
I had the same problem but with Apache. VirtualBox on Windows and Centos with httpd and php on docker. Problem fixed by changing httpd.conf parameter
#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall may be used to deliver
# files. This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
# Defaults if commented: EnableMMAP On, EnableSendfile Off
#
#EnableMMAP off
EnableSendfile off
EnableSendfile to off because
...but must be turned off when serving from networked-mounted filesystems...
Sending files still works good. Hope this will help someone.
来源:https://stackoverflow.com/questions/35187859/docker-on-windows-data-in-mounted-volume-doesnt-updated