我在 Windows 主页上使用 docker-toolbox。
我能够运行 jekyll-serve 网络服务器图像来查看浏览器上的默认页面,但是当我尝试在 VS Code 上编辑文件时,刷新浏览器后我看不到更改。
知道为什么刷新后看不到更改吗?
重现步骤:
首先我已经 git 克隆了这个 repository进入我的c:/Users/shaharshokrani/udemy-docker-mastery/bind-mount-sample1
(我可以在 'cmder' 控制台上看到带有 ls
的文件)。
然后我就可以运行这个 image和: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
但刷新浏览器后我看不到更改。
我还检查了共享网络的虚拟机 - 它显示 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-serve
、bretfisher/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
最佳答案
确定的问题
绑定(bind)安装实际上不适用于 docker 工具箱:
file change events in mounted folders of host are not propagated to container by Docker for Windows
解决方案
此脚本旨在解决此问题:docker-windows-volume-watcher .
边注
这是在容器外部操作数据的常见问题。
特别是对于 jekyll,即使下面问题中描述的解决方案也不适用于基于 Windows 的系统。
https://github.com/jekyll/jekyll-watch/issues/17
简而言之,您需要使用
--force_polling
执行 jekyll标志( 不适用于 Windows 主机 )。您可以在此处的 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 的更改的文件。
关于Docker 绑定(bind)挂载 - 在浏览器上看不到更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58962674/