Sub topic 13
Troubleshooting and known limitations
This chapter assumes you have already written a develop.watch section with sync, rebuild, sync+restart and sync+exec rules. It also assumes you can read container logs and run docker compose exec. The chapter gives you a fixed order for diagnosing a change that does not show up in the container. It then lists the limitations of Compose Watch that no configuration can remove.
A diagnostic order
When an edit on the host does not change what you see in the browser, the cause is in one of four places:
- Compose never started watching.
- Watch saw the file but no rule matched it.
- The rule ran but the file landed in the wrong place.
- The file arrived but the process inside the container never reloaded it.
Check them in that order. Each step rules out one layer.
Step 1: confirm that watch is running
Watch is not part of a plain docker compose up. You must start it with docker compose up --watch or with docker compose watch. Look for a message in the output saying that watch is enabled. If it is missing, you are not watching.
Two other causes produce no watch output:
- The service has no
buildsection. Watch only acts on services Compose builds itself. A service that uses onlyimage:is skipped, because there is nothing to rebuild and no build context to compare against. Compose prints a message naming the service it skipped. - The Compose version is too old. Watch needs Compose 2.22 or later.
sync+execarrived in a later release (2.32 or newer, so check the release notes for your version). An unknown action name in an older version fails validation.
docker compose version
docker compose configdocker compose config prints the merged, validated file. A YAML indentation mistake that moved develop out of the service shows up here, because the printed output will not contain develop.watch under the service.
Step 2: confirm that a rule matches
A rule matches when the changed file is under the rule's path, which Compose resolves relative to the project directory (the folder holding the Compose file). It must also not be excluded by an ignore pattern.
Common mistakes:
- A wrong or misspelled
path../srcdoes not match files in./app/src. - Patterns relative to the wrong place. Patterns in
ignoreandincludeare relative to the rule'spath, not to the project root. Withpath: ./src, the patternnode_modules/refers to./src/node_modules/. It does not refer to./node_modules/. - Overlapping rules. If one file falls under two rules, such as
./srcwithsyncand./src/package.jsonwithrebuild, both can act. Keep the paths of different actions apart where you can. - Ignore rules from
.dockerignore. Compose also applies your.dockerignore. A file listed there can be silently excluded from watch. - A change made while watch was not running. Watch reacts to file events after it starts. It does not compare the whole tree at start-up. If you edited files before starting watch, the container still has what was baked into the image. Run
docker compose up --build --watchonce to start from a fresh image.
Changes to compose.yaml itself are not picked up by watch. After editing the file, stop watch and start it again.
Step 3: confirm that the file arrived at the right place
Look inside the container instead of guessing. Sync copies a file to target, and the Dockerfile decides what target should be.
docker compose exec web ls -l /app/src
docker compose exec web cat /app/src/index.jsIf the file is missing or old, check these in order:
targetdoes not matchWORKDIRandCOPY. The Dockerfile in this series usesWORKDIR /appandCOPY . ., so source files live in/appand the sync target for./srcis/app/src. If you changeWORKDIR, update everytarget.- Permissions. Sync writes as the container's
USER. If the Dockerfile switches to a non-root user, that user must be able to write to the target directory. Files you copied with plainCOPYare owned by root, so useCOPY --chown=node:nodefor them. - A missing helper tool. Sync relies on a few basic utilities inside the container, such as
stat,mkdirandrmdir. Images with no shell or core utilities, such asscratchor distroless images, cannot be synced. Use a normal base image for the development target. - Compose-level filtering. A rule with
includecopies only matching files. If your edit does not match any include pattern, nothing is copied.
A working configuration that avoids these problems looks like this:
services:
web:
build: .
ports:
- "3000:3000"
develop:
watch:
- action: sync
path: ./src
target: /app/src
ignore:
- "*.test.js"
- action: rebuild
path: package.jsonFROM node:20-alpine
WORKDIR /app
COPY --chown=node:node package*.json ./
RUN npm install
COPY --chown=node:node . .
USER node
CMD ["npm", "start"]Step 4: confirm that the process reloads the file
This is the most common cause when the file did arrive. Sync only puts bytes on disk. A Node.js process started with node server.js loaded the old module at start-up and does not look at the disk again. Pick one of these fixes:
- Run a tool that watches files inside the container, such as
nodemon, a Vite dev server, or Django'srunserver. - Change the rule to
sync+restart, which copies the file and then restarts the container. - Use
sync+execto run a command, such as a reload signal, after the copy.
docker compose logs -f webWatch the logs while you save a file. A reloader prints a restart line each time. If nothing prints, the process is not looking.
Watchers inside a container rely on file system events. Files written by sync generate normal events, so most reloaders work. If yours does not, switch it to polling mode.
Rebuild problems
A rebuild rule rebuilds the image and recreates only that service. It does not restart the services it depends on. If the rebuild finishes but the old behavior remains, look at the build cache. In the Dockerfile above, a change to package.json invalidates the COPY package*.json layer, so npm install reruns. A change to the lock file you did not list in the rule does not trigger a rebuild. Add the lock file as its own rebuild rule, for example package-lock.json.
If a rebuild fails, the old container keeps running with the old code. Read the build output, because a failed rebuild can look like "my change did nothing".
Symptom summary
| Symptom | Likely cause | Fix |
|---|---|---|
| No watch message at start | Started with plain `up` | Use `up --watch` or `watch` |
| Service ignored by watch | No `build` section | Add `build:` to the service |
| Unknown action error | Old Compose version | Upgrade Compose |
| Edit before start-up missing | Watch reacts to events only | Run `up --build --watch` |
| File missing in container | Wrong `target` or `WORKDIR` | Compare with `ls` in the container |
| Permission denied on sync | Non-root `USER`, root-owned folder | Use `COPY --chown` |
| File present but behavior old | Process does not reload | Use a reloader or `sync+restart` |
| Dependency change not applied | No `rebuild` rule for that file | Add a rule for the manifest and lock file |
| `node_modules` overwritten or slow | Missing `ignore` | Add `node_modules/` to `ignore` |
Known limitations
These are properties of the feature, so configuration cannot fix them:
- Only built services. Services that use a pre-built
image:with nobuildsection cannot be watched. - Needs a regular container file system. Shell-less and Windows containers are not supported for sync.
- One direction only. Files go from host to container. Files that the container writes, such as generated code or lock files, do not come back to the host.
- No start-up comparison. Watch does not reconcile differences that existed before it started.
- Compose file changes need a manual restart of watch.
- Large trees cost resources. Watching a very large directory, or one that includes build output, creates many events. Narrow
pathvalues and useignoreto cut them down.
> A tip on scope: you can keep a bind mount for one special directory, such as a data folder, and use watch for the source. The two can coexist, as long as they do not target the same path.
Exercise
You run docker compose up -d and then edit src/app.js. The container still serves the old version. The file develop.watch is correct and the web service has a build section. What is the most likely cause, and what do you run?
Show answer
Watch was never started, because up -d alone does not enable it. Run docker compose watch (the services are already running), or docker compose up --watch. Because the edit happened before watch started, also run docker compose up --build --watch once so the container begins from an up-to-date image.
Exercise
docker compose exec web cat /app/src/app.js shows your latest edit, but the browser still shows the old behavior. The service runs node server.js. Name two ways to fix this.
Show answer
Sync worked, but the Node process loaded the old file at start-up and never rereads it. Either run the app under a reloader such as nodemon so it restarts on file changes, or change the rule's action to sync+restart so Compose restarts the container after each copy. A sync+exec rule that sends a reload signal also works.