Docker toolbox volumes on windows doesn't refresh changes on container

落爺英雄遲暮 提交于 2021-02-08 07:10:24

问题


I am starting with docker on windows and I am trying to use volumes for manage data in containers.

My host environment is a:

  • Windows 8.1
  • Docker Toolbox 1.8.
  • Virtual Box 5.0.6

I've created a ngnix image using the following Dockerfile.

Dockerfile

FROM centos:6.6

MAINTAINER afym

ENV WEBPORT 80

RUN yum -y update; yum clean all
RUN yum -y install epel-release; yum clean all
RUN yum -y install nginx; yum clean all
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

VOLUME /usr/share/nginx/html

EXPOSE $WEBPORT

CMD [ "/usr/sbin/nginx" ]

I've created a ngnix container using the following command.

docker run -d --name nge -v //c/Users/src:/usr/share/nginx/html -p 8082:80 ng1

b738fef9cc4d135416a8cca4caf869acf944319b7c3c61129b11f37f9d891598

Then I go to my browser and I can see the web page:

However when I make a change on my index.html file it doesn't refresh on browser

Editing my file

On my browser (ctrl + f5)

I went to the VirtualBox machine to check if my shared directories options is ok.

Then I inspect my nge container with the following command.

docker inspect ng1

Docker inspect

What is happening with volumes? Why I can not see my changes?


回答1:


After a couple of days I could find the solution.

Firstable docker on windows even on MAC uses a boot2docker instance on VirtualBox.

Diagrams

On MAC

On Windows

Next, the official docker's documentation says :

docker volume

Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory

However, after find a solution I decided to change the default c/Users to another path just for keep order. With this in mind I did the following steps:

  • Define your own workspace directory. In my case is /e/arquitectura (optional. If you want you can use the default path which is /c/Users)
  • Verify the configuration on the Virtual Machine (In default machine go to > Configuration > Share directories)

  • Join to the default machine and mount the directory using the alias name
  sudo mount -t vboxsf alias-name-virtualbox  some-path-in-boot2docker

  # In my case (boot2docker instance)
  $ cd
  $ mkdir arquitectura
  $ sudo mount -t vboxsf arquitectura /arquitectura 
  • Finally create a new container or restart an existing one if you haven't changed the c/user/ path
# In my case (docker client)
$ docker run -d --name nge -v //arquitectura/src:/usr/share/nginx/html -p 8081:80 ng1

Now it works.



来源:https://stackoverflow.com/questions/33352104/docker-toolbox-volumes-on-windows-doesnt-refresh-changes-on-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!