File Watchers in a Container Miss Host Edits Unless They Poll

In progress Docker

On macOS and Windows, Docker runs containers inside a Linux VM (Docker Desktop, Colima). A bind-mounted project folder reaches that VM through a file-sharing layer (virtiofs, sshfs, 9p) that doesn't always forward change notifications. A dev server or CSS compiler waiting for inotify events then never hears about saved files: the code changes on the host, nothing rebuilds in the container. Switching the watcher to polling, which rescans files on an interval, works on any mount.

Why the Events Disappear

Linux watchers rely on inotify: the kernel tells them when a file in a watched directory changes. When the edit happens on the macOS host, the guest kernel only learns about it if the sharing layer translates the host's event into an inotify event inside the VM. Some setups do, some don't, and some lose events under load.

Colima, for example, runs a Lima VM with the macOS hypervisor framework, forwards the VM's Docker socket to the host, and mounts host folders into the VM so containers can bind-mount them.

Use Polling in Development

Most watchers have a polling switch:

Tool Polling option
Uvicorn (--reload) uses watchfiles; WATCHFILES_FORCE_POLLING=true
Tailwind CSS CLI --poll
webpack / Vite watchOptions.poll / server.watch.usePolling
nodemon --legacy-watch

Run the Watcher Beside the App, Not Inside It

Starting a compiler watcher from the web app's own startup code (a FastAPI lifespan hook spawning tailwindcss --watch) couples a development tool to the server process: the watcher runs in production images too, uses memory there, and can be left behind as a zombie process when the server reloads or stops.

References

Review cards

Flashcard Why do file watchers in a container miss host edits on macOS and Windows?

Because the file-sharing layer (virtiofs, sshfs, 9p) doesn't always forward change notifications from the host to the guest VM, and Linux watchers rely on inotify, which may not receive events from the host.

Flashcard What is the potential downside of running a file watcher inside the web app's startup code?

It couples the development tool to the server process, which can run in production images and leave behind a zombie process when the server reloads or stops.