Docker bound mount - can not see changes on browse

2020-04-17 06:30发布

问题:

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

回答1:

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 jekyll