Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

node.js - Nodemon Doesn't Restart in Windows Docker Environment

My goal is to set up a Docker container that automatically restarts a NodeJS server when file changes are detected from the host machine.

I have chosen nodemon to watch the files for changes.

On Linux and Mac environments, nodemon and docker are working flawlessly.

However, when I am in a Windows environment, nodemon doesn't restart the server.

The files are updated on the host machine, and are linked using the volumes parameter in my docker-compose.yml file.

I can see the files have changed when I run docker exec <container-name> cat /path/to/fileChanged.js. This way I know the files are being linked correctly and have been modified in the container.

Is there any reason why nodemon doesn't restart the server for Windows?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use nodemon --legacy-watch to poll for file changes instead of listening to file system events.

VirtualBox doesn't pass file system events over the vboxfs share to your Linux VM. If you're using Docker for Windows, it would appear HyperV doesn't propagate file system events either.

As a 2021 side note, Docker for Mac/Windows new GRPCfuse file system for mounting local files into the VM should send file system events across now.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...