Docker重新启动不显示所需的效果 [英] Docker restart not showing the desired effect

查看:139
本文介绍了Docker重新启动不显示所需的效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型的基于nginx的测试应用程序,我想在docker容器内运行。所以我按照这里给出的例子。码头安装

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

所以我有一个foder名称 restartTest ,它包含一个index.html文件,其中有一行表示 Docker Test 1 。我在Docker容器的运行期间将其挂载为我的卷。所以我使用的commmand是

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

它运行正常。我使用curl来验证卷已正确安装,并且应用程序正在运行。现在我所做的是将index.html文件 (从我的本地主机)更改为Docker test 2 ,然后重新启动容器。我执行以下命令来验证Docker容器内的内容确实已经改变了。

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

正如所料,文件读取测试2 。但是,当我使用curl命令查看网页是否也反映了这个变化时,我看到我仍然将 Docker Test 1 作为响应。当我运行curl命令或者我从浏览器访问应用程序时,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. 重新启动服务

  2. 停止并启动容器

  3. 停止并启动boot2docker VM和docker守护程序。

我没有线索为什么会发生这种情况。

I have no clue as to why this is happening.

推荐答案

所以我发现这个已知的错误与VirtualBox VM用于在Mac上运行Docker。
当我们在主机和VirtualBox之间共享内容时,只有我们面临这个错误。就像nginx,apache(和显然是vertx)这样的网络服务器有一个优化。每当我们从服务器请求一个静态文件时,它使用 sendfile 为我们提供文件。错误是,在VirtualBox的情况下(在上述情况下),无论我们尝试什么,我们总是获得该文件的第一个版本。在nginx和apache的情况下,解决方法是关闭sendfile。但是,对于vertx而言,我们使用的是一个黑客。

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. 将login.html重命名为login.html。移动(任何)

  2. curl:/ ... ... / login.html(我们不会得到任何东西)

  3. 将文件重命名为其原名为login.html.moved to login.html

  4. 硬刷新页面(Command + Shift + R)。

  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

这篇关于Docker重新启动不显示所需的效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆