Docker绑定安装-在浏览器上看不到更改 [英] Docker bound mount - can not see changes on browser

查看:94
本文介绍了Docker绑定安装-在浏览器上看不到更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows Home上使用docker-toolbox. 我可以运行jekyll-serv Web服务器图像来查看浏览器上的默认页面,但是当我尝试在VS Code上编辑文件时,刷新浏览器后看不到更改.

您知道刷新后为什么看不到更改吗?


复制步骤:

首先,我已经git克隆了这个存储库放入我的c:/Users/shaharshokrani/udemy-docker-mastery/bind-mount-sample1(我可以在'cmder'控制台上使用ls查看文件).

然后,我可以使用以下方式运行此图像:

docker run -v //c/users/shaharshokrani/udemy-docker-mastery/bindmount-sample-1:/site bretfisher/jekyll new .

docker container run -p 80:4000 --name myjekyll -v //c/users/shaharshokrani/udemy-docker-mastery/bindmount-sample-1:/site bretfisher/jekyll-serve

我可以在http://192.168.99.100/上看到默认的欢迎页面.

我尝试使用VS Code编辑和保存此2017-03-05-welcome-to-jekyll.markdown,但是刷新浏览器后看不到更改.


我还检查了VM的共享网络-它显示c:/users/.

即使检查中的Mounts看起来也不错:

"Mounts": [
    {
        "Type": "bind",
        "Source": "/c/users/shaharshokrani/udemy-docker-mastery/bindmount-sample-1",
        "Destination": "/site",
        "Mode": "",
        "RW": true,
        "Propagation": "rprivate"
    }
],

并且图像 dockerfile CMD具有--force_polling标志.

两个图像(bretfisher/jekyll-servebretfisher/jekyll)都是最新的.

docker container logs -f myjekyll看起来不错:

Bundle complete! 4 Gemfile dependencies, 28 gems now installed.
Bundled gems are installed into `/usr/local/bundle`
Configuration file: /site/_config.yml
            Source: /site
       Destination: /site/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
                    done in 1.031 seconds.
 Auto-regeneration: enabled for '/site'
    Server address: http://0.0.0.0:4000/
  Server running... press ctrl-c to stop.


Docker版本:

Client:
 Version:       18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24302
 Built: Fri Mar 23 08:31:36 2018
 OS/Arch:       windows/amd64
 Experimental:  false
 Orchestrator:  swarm

Server: Docker Engine - Community
 Engine:
  Version:      19.03.3
  API version:  1.40 (minimum version 1.12)
  Go version:   go1.12.10
  Git commit:   a872fc2f86
  Built:        Tue Oct  8 01:01:20 2019
  OS/Arch:      linux/amd64
  Experimental: false
 containerd:
  Version:      v1.2.10
  GitCommit:            b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:      1.0.0-rc8+dev
  GitCommit:            3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:      0.18.0
  GitCommit:            fec3683

解决方案

问题已识别

绑定安装实际上不适用于docker工具箱:

主机的已安装文件夹中的

文件更改事件不会传播到 Docker for Windows的容器

解决方案

该脚本旨在解决此问题: docker-windows-volume -观察者.


旁注

这是在容器外部操作数据的常见问题.

特别是对于jekyll,即使以下问题中描述的解决方案也不适用于基于Windows的系统.

https://github.com/jekyll/jekyll-watch/issues/17

简而言之,您需要使用--force_polling标志(不适用于Windows主机)来执行jekyll.您可以在jekyll文档中找到它

https://jekyllrb.com/docs/configuration/options/


在基于Linux的系统上,它可以直接使用,因为问题bretfisher/jekyll-serve中使用的图像已经利用了--force_polling标志.

刚跑

docker run --rm -it -e JEKYLL_NEW=true -p 8080:4000 -v (pwd):/site bretfisher/jekyll new . 

创建一个新的jekyll网站和

docker run --rm -it -e JEKYLL_NEW=true -p 8080:4000 -v (pwd):/site bretfisher/jekyll-serve                                                  

将其安装到我的计算机(linux)上的目录中运行,并能够通过传播到jekyll的方式编辑文件.

I'm using docker-toolbox on windows home. I was able to run a jekyll-serve web server image to see the default page on browser, but when I try to edit file on VS Code, I can not see the changes after refreshing the browser.

Any idea why I can not see the changes after refresh?


Step to reproduce:

First I've git cloned this repository into my c:/Users/shaharshokrani/udemy-docker-mastery/bind-mount-sample1 (I'm able to see the files with ls on 'cmder' console).

Then I was able to run this image with:

docker run -v //c/users/shaharshokrani/udemy-docker-mastery/bindmount-sample-1:/site bretfisher/jekyll new .

docker container run -p 80:4000 --name myjekyll -v //c/users/shaharshokrani/udemy-docker-mastery/bindmount-sample-1:/site bretfisher/jekyll-serve

And I'm able to see the default welcome page on http://192.168.99.100/.

I've tried to edit and save using VS Code this 2017-03-05-welcome-to-jekyll.markdown but I can not see the changes after refreshing the browser.


I also checked the VM for shared network - it shows c:/users/.

Even the Mounts on inspect looks good:

"Mounts": [
    {
        "Type": "bind",
        "Source": "/c/users/shaharshokrani/udemy-docker-mastery/bindmount-sample-1",
        "Destination": "/site",
        "Mode": "",
        "RW": true,
        "Propagation": "rprivate"
    }
],

And the image dockerfile's CMD has the --force_polling flag.

Both the images (bretfisher/jekyll-serve, bretfisher/jekyll) are latest.

The docker container logs -f myjekyll looks good:

Bundle complete! 4 Gemfile dependencies, 28 gems now installed.
Bundled gems are installed into `/usr/local/bundle`
Configuration file: /site/_config.yml
            Source: /site
       Destination: /site/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
                    done in 1.031 seconds.
 Auto-regeneration: enabled for '/site'
    Server address: http://0.0.0.0:4000/
  Server running... press ctrl-c to stop.


Docker version:

Client:
 Version:       18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24302
 Built: Fri Mar 23 08:31:36 2018
 OS/Arch:       windows/amd64
 Experimental:  false
 Orchestrator:  swarm

Server: Docker Engine - Community
 Engine:
  Version:      19.03.3
  API version:  1.40 (minimum version 1.12)
  Go version:   go1.12.10
  Git commit:   a872fc2f86
  Built:        Tue Oct  8 01:01:20 2019
  OS/Arch:      linux/amd64
  Experimental: false
 containerd:
  Version:      v1.2.10
  GitCommit:            b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:      1.0.0-rc8+dev
  GitCommit:            3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:      0.18.0
  GitCommit:            fec3683

解决方案

Issue identified

Bind mounting actually does not work for docker toolbox:

file change events in mounted folders of host are not propagated to container by Docker for Windows

Solution

This script is intended to be the answer to this issue: docker-windows-volume-watcher.


Side note

This is a common issue with data manipulated outside of your container.

For jekyll, in particular, even the solution described in the issue below does not work for windows-based systems.

https://github.com/jekyll/jekyll-watch/issues/17

In short you need to execute jekyll with the --force_polling flag (Does not work with Windows Hosts). You can find it in the jekyll docs here

https://jekyllrb.com/docs/configuration/options/


On Linux based systems it works out of the box since the image used in the question bretfisher/jekyll-serve already utilizes the --force_polling flag.

just ran

docker run --rm -it -e JEKYLL_NEW=true -p 8080:4000 -v (pwd):/site bretfisher/jekyll new . 

to create a new jekyll site and

docker run --rm -it -e JEKYLL_NEW=true -p 8080:4000 -v (pwd):/site bretfisher/jekyll-serve                                                  

to run it mounted to a directory on my machine (linux) and was able to edit a file with changes propagating to jekyll.

这篇关于Docker绑定安装-在浏览器上看不到更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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