Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit notifications don't work when running inside of Docker container on Windows #292

Closed
matt-github-acct opened this issue Apr 28, 2019 · 10 comments

Comments

@matt-github-acct
Copy link

I'm running Windows 10 Enterprise, 10.0.17134

My goal is to launch a docker container, mount a volume inside the container, edit files in the volume from my host operating system and have the docker container recognize the change events. Pretty much this: https://www.zachjohnsondev.com/posts/go-docker-hot-reload-example/

Steps to reproduce

  1. Create main.go file and add the following:
package main

import (
	"log"

	"github.com/fsnotify/fsnotify"
)

func main() {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}
	defer watcher.Close()

	done := make(chan bool)
	go func() {
		for {
			select {
			case event, ok := <-watcher.Events:
				if !ok {
					return
				}
				log.Println("event:", event)
				if event.Op&fsnotify.Write == fsnotify.Write {
					log.Println("modified file:", event.Name)
				}
			case err, ok := <-watcher.Errors:
				if !ok {
					return
				}
				log.Println("error:", err)
			}
		}
	}()

	err = watcher.Add(".")
	if err != nil {
		log.Fatal(err)
	}
	<-done
}

  1. Create a docker-compose file and add the following:
version: "3.6"

services:
  bar:
    container_name: bar
    build: .
    ports:
      - "8080:8080"
    volumes:
      - ./:/go/src/bar
  1. Create a Dockerfile file and add the following:
FROM golang:latest

WORKDIR /go/src/bar

COPY . .

RUN ["go", "get", "github.com/fsnotify/fsnotify"]

ENTRYPOINT go run main.go
  1. Run docker-compose build in the directory where you've created the files.
  2. Run docker-compose up in the directory where you've created the files.
  3. From your host operating system, add a comment to main.go and notice that no edit events are reported.
  4. Run docker exec -it bar bash to connect to the docker container. Edit main.go from the container shell to confirm that edit events are being reported when the edit is performed within the container.
@oxycoder

This comment was marked as duplicate.

@nathany
Copy link
Contributor

nathany commented Oct 5, 2019

I'm not sure how Docker for Windows is mounting the shared folder, but generally file shares such as NFS don't support notifications.

A polling fallback (#9) is the only solution I know of when the underlying system doesn't provide events.

For now we should document the limitation, but first we should confirm on other operating systems. It may work on Linux, depending on how the Docker container is mounted there.

@oxycoder
Copy link

oxycoder commented Oct 6, 2019

Currently it work perfectly fine with folder mount to docker on MacOS.

@julienkosinski
Copy link

julienkosinski commented Nov 15, 2019

I can confirm it works well under on Docker with Linux host (Manjaro distro).

@jnach
Copy link

jnach commented Jan 6, 2020

I can confirm it works well under on Docker with Linux host (Manjaro distro).

Which storage driver do you happen to be using? With @nathany's comment in mind, this could be filesystem dependent. In both 'working' cases, this sounds like a bind mount, not a K8's storage driver under the PVC subsystem

@jnach
Copy link

jnach commented Jan 6, 2020

This seems to do a good job of explaining the phenomenon here..

@jnach
Copy link

jnach commented Jan 6, 2020

Same problem, any solutions?

Sorta, see above. TL&DR This is a file-system compatibility issue. There are a few scenarios where it works when using the same underlying host filesystem, but pretty much never if there is any translation.

@reyronald

This comment was marked as duplicate.

@Hanggi

This comment was marked as duplicate.

@arp242
Copy link
Member

arp242 commented Oct 14, 2022

Closed as duplicate of #9; if the underlying OS mechanism doesn't work then there's not much we can do about it other than implement a polling fallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants