🐳 Docker: Fix compose watch Ignoring a Renamed Source File
Compose’s watch feature (the built-in replacement for a lot of bind-mount-plus-nodemon dev setups) tracks changes by watching the specific paths listed under each service’s develop.watch entries, matching against the path and any ignore globs you’ve configured — and that file-system watcher reacts to write and modify events on existing paths, not to a rename. Renaming a tracked source file is, from the underlying filesystem notification API’s point of view, a delete of the old path followed by a create of a new one, and if the new filename happens to fall outside the configured path pattern (a slightly different extension, a path depth the glob didn’t anticipate) compose watch silently stops tracking it from that point on, with no error and no log line calling out that a watched path just disappeared.
🔎 The Problem
# compose.yaml
services:
web:
develop:
watch:
- action: sync
path: ./src
target: /app/src
ignore:
- "**/*.test.js"
# Developer renames src/handlers/order.js -> src/handlers/orderHandler.js
# while docker compose watch is running:
$ docker compose watch
[+] watch sync initial scan complete
-> watching src/handlers/order.js # tracked
-> (no corresponding line ever appears for orderHandler.js)
# Edits to orderHandler.js afterward never sync into the container -
# the running app keeps serving the stale old file's compiled output
✅ Fix: Restart the Watcher After Any Rename, and Watch Directories Not Files
- Point
develop.watch[].pathat the containing directory (./src) rather than individual filenames wherever possible — a directory-level watch picks up a new filename on its next scan the moment a file appears under it, instead of needing to already know that exact name in advance. - Restart
docker compose watchafter any rename or move of a tracked file during active development — the watcher’s internal path list is built once at startup from the filesystem state at that moment, and it has no live reconciliation step that notices a tracked path vanished. - Add a quick sanity check to the dev workflow (a wrapper script, or just a habit) that runs
docker compose watchwith--no-upand-vbriefly after a bulk rename, confirming every expected path still shows up in the initial scan log before trusting the session to sync correctly.
🚨 Why This Is Dangerous
- The container keeps running and keeps responding, so a renamed file that silently stopped syncing looks identical to a working dev loop right up until someone spends real time debugging why their latest code change “isn’t taking effect,” when the container is actually still running the file from before the rename.
compose watch tracks paths, not intent — and a rename that your editor shows as one smooth operation is, to a filesystem watcher, an old path disappearing and a new one it was never told to look for.




