Hot Reloading Node and React on Docker Windows

Ever since I moved my development environment to Windows, it has been a constant struggle to emulate the previous environment that I had built on OSX.

Probably one of the most critical components in my projects is the fact that all of my projects run on a Docker microservice architecture. In addition to the usual isolation and scalability advantages, development becomes a joy especially when you use filesystem watchers on NodeJS (nodemon) and ReactJS (react-scripts) that enable hot-reloading.

The problem is that, out of the box, these file watchers do not work on Windows 10. The reason is that to run Linux container on Windows 10, you need to have Hypervisor, which acts as a virtualization layer - hence all virtualization rules apply to hot-reloading!

In other words, in order for hot reloading to work on Docker Windows, you need to enable Chokidar polling.

How do fix Hot Reloading with Chokidar?


For NodeJS, just modify the package.json file to use the legacy mode when starting nodemon. This can be easily done using the -L flag.

  "scripts": {
    "server": "nodemon -L index.js"
  },

For ReactJS, it is equally simple. Just add a .env file inside the project parent directory (/usr/src/app) with the following line:

CHOKIDAR_USEPOLLING=true

Post a Comment