0

I have a small nginx based test application that I want to run inside a docker container. So I followed the example given here docker installation

So I have a foder name restartTest and it contains an index.html file that has this single line in it that says Docker Test 1. I mount this up as my volume during runtime for docker container. So the commmand I use is

docker run -dP -v /Users/Sachin/restartTest/:/usr/share/nginx/html --name engine2 nginx

And it runs fine. I use curl to verify that the volume has mounted properly and the application is running as desired. Now what I do is that I change the content of the index.html file (from my localhost) to Docker test 2 and then I restart the container. I execute the following command to verify that the content has indeed changed inside the docker container

docker exec engine2 cat /usr/share/nginx/html/index.html

And as expected, the file reads Docker Test 2. However, when I use the curl command to see if the webpage also reflects the change I see that I still get Docker Test 1 as the response. The index.html reflects the change however when I run the curl command or if I access the app from the browser, I still get the same result. I have tried the following but to no avail.

  1. Restart the service
  2. Stop and start the container
  3. Stop and start the boot2docker VM and docker daemon.

I have no clue as to why this is happening.

Sachin Malhotra
  • 1,211
  • 2
  • 11
  • 24

2 Answers2

2

So I found this known bug with VirtualBox VM that is used for running Docker on Mac. When we have shared content between our host machine and the VirtualBox, then only we face this bug. There is a optimisation as far as web servers like nginx, apache (and apparently vertx) are concerned. Whenever we request a static file from the server, it uses sendfile to provide us with the file. The bug is that in case of VirtualBox (in the scenario described above) we always get the first version of the file no matter what we try. The workaround for this in case of nginx and apache is to turn sendfile off . However, there is a hack that we use as far as vertx is concerned.

  1. rename the file say login.html to login.html.moved (anything)
  2. curl :/….../login.html (we won’t get anything)
  3. rename the file back to its original name login.html.moved to login.html
  4. Hard refresh the page (Command + Shift + R).

For further reading about this bug consult the following

Link1

Link2

Link3

Link4

Sachin Malhotra
  • 1,211
  • 2
  • 11
  • 24
0

I assume it is a caching problem. Did you try to set expires -1 in your index.html location configuration to disable server side caching for static files?

Henrik Sachse
  • 51,228
  • 7
  • 46
  • 59
  • This problem is not with nginx only. I also have a vertx3 application and it also has a static web page namely login.html. I face the same problem there. I make some changes and I can see the changes (using vim inside the container, but they don't reflect on the web page. Weird issue :( ) – Sachin Malhotra Jul 27 '15 at 11:19