简体   繁体   English

在主机上更改已装入卷中的文件时,未在docker容器中触发文件系统事件

[英]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. 更改文件后,我想使用nodemon重新启动项目。 I think nodemon works by listening for inotify events to trigger reloading a node.js project. 我认为nodemon通过侦听inotify事件来触发重新加载node.js项目。

The project runs in a docker container, and the project files are in a mounted volume. 该项目在docker容器中运行,并且项目文件在已安装的卷中。

When the project files are edited from inside the docker container, for example 例如,从Docker容器内部编辑项目文件时

docker-compose exec dev vim server.js

nodemon works correctly and restarts the server. nodemon可以正常工作,然后重新启动服务器。

However, when an editor running on the host machine is used, nodemon does not pick up the changes and restart the program. 但是,使用在主机上运行的编辑器时,nodemon不会获取更改并重新启动程序。

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. 实际上,docker容器中文件的内容确实发生了变化,因此我怀疑以这种方式编辑文件不会触发FS事件。

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? 是否可以进行设置,以便在主机上编辑文件导致文件系统事件在Docker容器中发生? Why does this not happen already? 为什么还没有发生呢?

Platform Info: 平台信息:
  • Docker for Windows (Hyper-V) Windows版Docker(Hyper-V)
  • node docker container node docker容器
  • WebStorm -- Host based editor WebStorm-基于主机的编辑器

It looks like file system events just don't work when Docker is running in Hyper-V and the changes happen on the host. 当Docker在Hyper-V中运行并且更改发生在主机上时,文件系统事件似乎不起作用。 But, it's possible to work around that limitation by enabling polling in nodemon: 但是,可以通过在nodemon中启用轮询来解决该限制:

nodemon -L server.js

In WebStorm the full command that ends up getting used is 在WebStorm中,最终使用的完整命令是

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

More info: https://github.com/remy/nodemon#application-isnt-restarting 更多信息: https : //github.com/remy/nodemon#application-isnt-restarting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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