nodemon in Docker: legacy polling vs native file events for mounted volumes
0 reputation · 04 Jun 2023, 18:35 UTC
I'm running a Node.js app inside a Docker container with the source directory bind-mounted from the host, and I use nodemon for automatic restarts during development. I need to pick a watching strategy that stays reliable without making the dev container unusable.
From the documentation, nodemon defaults to native OS file system events, which are fast and cheap, but those events are reported to be unreliable when a volume is mounted from a Windows or macOS host. The alternative is the -L / --legacy-watch polling mode, which checks timestamps on an interval and works on networked or virtualized file systems, at the cost of higher CPU usage that grows with project size.
My constraints: the project tree is fairly large (including node_modules, which I can exclude via nodemon.json), and several developers use different host operating systems, so the choice has to live in shared configuration rather than per-machine flags.
Given a large bind-mounted project, is legacy polling with a tuned interval and ignore list the accepted trade-off, or is there a documented way to keep native events working across hosts? What polling interval is a reasonable starting point before CPU overhead becomes a real problem?