Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 951
RyanNHG Avatar asked Aug 31 '16 02:08

RyanNHG


People also ask

How do I restart Nodemon?

Running non-Node code While Nodemon is running, we can manually restart our application. So instead of stopping and restarting Nodemon, we can just type rs and press enter, and Nodemon will restart the server or the running process for us.

What is Nodemon JSON?

nodemon supports local and global configuration files. These are named nodemon. json and can be located in the current working directory or in your home directory. The specificity is as follows, so that a command line argument will always override the config file settings: command line arguments.


2 Answers

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.

2022 note: Looks like Windows/WSL Docker doesn't share FS events to the Linux VM (see comments @Mohamed Mirghani and @Ryan Wheale).

like image 67
Matt Avatar answered Sep 20 '22 02:09

Matt


It is simple, according to the doc you must change:

nodemon server.js 

to:

nodemon --legacy-watch server.js 
like image 43
Masih Jahangiri Avatar answered Sep 22 '22 02:09

Masih Jahangiri