简体   繁体   中英

File system events not triggered in docker container when files in mounted volume are changed on the host

I would like to use nodemon to restart my project when its files are changed. I think nodemon works by listening for inotify events to trigger reloading a node.js project.

The project runs in a docker container, and the project files are in a mounted volume.

When the project files are edited from inside the docker container, for example

docker-compose exec dev vim server.js

nodemon works correctly and restarts the server.

However, when an editor running on the host machine is used, nodemon does not pick up the changes and restart the program.

The contents of the files in the docker container do in fact change, so I suspect editing files this way just doesn't trigger an FS event.

Is it possible to set this up so that editing files on the host machine causes file system events to occur in the Docker container? Why does this not happen already?

Platform Info:
  • Docker for Windows (Hyper-V)
  • node docker container
  • WebStorm -- Host based editor

It looks like file system events just don't work when Docker is running in Hyper-V and the changes happen on the host. But, it's possible to work around that limitation by enabling polling in nodemon:

nodemon -L server.js

In WebStorm the full command that ends up getting used is

docker-compose run dev node node_packages/nodemon/bin/nodemon.js -L server.js

More info: https://github.com/remy/nodemon#application-isnt-restarting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM