File watch mode doesn't work in docker
Describe the bug When using Docker with a local volume, as described in the docs, the server doesn't respond to file changes in the mounted volume.
To Reproduce Create local directories, e.g.
test/
├── mocks/
│ ├── routes/
│ │ └── route.json
│ └── collections.json
with a valid routes and collections in route.json and collections.json respectively.
Then run mocks-server in docker mounting the test directory as a volume
docker run -ti -p 3100:3100 -p 3110:3110 -v C:\test:/input mocksserver/main
Go to the URL configured in route.json, it should return as expected. Now change the route in route.json so that it returns something else. It will continue to return the initial response.
Expected behavior
If a file in the mocks/ directory is updated, the mocks-server should pick up that change and server whatever the current response is.
Operating system, Node.js an npm versions, or browser version (please complete the following information):
- OS: Windows 10
- Docker: 20.10.22
Additional context If you open a shell inside the docker container and check the file, it is updated as expected, so it seems to be mocks-server not responding to the file change rather than docker not updating the file inside the container.
Hi @timbarclay ,
You're right, thank your for sharing! The core of the project is using node-watch for watching the files, and it seems to be a wrapper for the node method fs.watch. I have just found a caveat about that method in the NodeJS documentation:
If the underlying functionality is not available for some reason, then fs.watch will not be able to function. For example, watching files or directories can be unreliable, and in some cases impossible, on network file systems (NFS, SMB, etc), or host file systems when using virtualization software such as Vagrant, Docker, etc.
So, this issue has not an easy solution, apart from trying to find another library without problems with virtualization, and replace the dependency.