Sub topic 13
Troubleshooting and known limitations
This chapter assumes you can write a Compose file with a build section, you know what the sync, rebuild, sync+restart and sync+exec actions do, and you have run docker compose watch at least once. It covers what to check when a host change does not show up in the container, and which limits of Compose Watch you should plan around.
Start with a checklist
Most failures fall into a few groups. Work through them in order, because the early checks are the cheapest.
Watch is not running
Editing develop.watch does nothing by itself. Watching starts only with docker compose up --watch, or with docker compose watch after the services are up. If you started with plain docker compose up, the containers run but no file events are handled. Compose prints the watch activity in the terminal, so look there for sync and rebuild messages.
The service has no build section
Compose Watch works on services it builds. A service that only has image: has nothing to rebuild, and Compose reports that the service needs a build section. Add one, and make sure the Dockerfile copies your code into the image, because sync places files in a path that already exists in the image layout.
Paths and patterns do not match
pathis relative to the project directory (where the Compose file lives), not to the container.targetis a path inside the container. A typo here syncs files to a place your app never reads.ignorepatterns are relative topath. Writingignore: - src/node_modules/underpath: ./srcmatches nothing, whilenode_modules/matches.- Patterns from
.dockerignorealso apply, so a file listed there will not be synced even if noignoreentry mentions it.
The container cannot write the target
The sync step copies files as the container's user. If your image switches to a non-root user, the target directory must be writable by that user. Set ownership at copy time:
FROM node:20-alpine
WORKDIR /app
COPY --chown=node:node package*.json ./
RUN npm install
COPY --chown=node:node . .
USER node
CMD ["npm", "start"]Sync also relies on basic tools such as stat, mkdir and rmdir being present in the image. Minimal images that remove them can break syncing.
The file arrives but the app does not change
Watch only delivers files. Your process still has to notice them. Interpreters and servers that load configuration once at startup will keep the old values. For those files use sync+restart:
services:
web:
build: .
develop:
watch:
- action: sync
path: ./src
target: /app/src
- action: sync+restart
path: ./config
target: /app/configIf your framework has its own reloader (for example a dev server with hot reload), confirm it is enabled in the container command. Some reloaders also depend on file system events, and a copied file should trigger them, but check the tool's documentation if it does not.
Known limitations
| Limitation | Practical effect |
|---|---|
| Needs a `build` section | Image-only services cannot be watched. |
| Sync is one-way, host to container | Files the container writes (generated code, lock files) do not come back. |
| Rules need the right action per file type | A dependency manifest under `sync` updates the file but does not reinstall packages. Use `rebuild`. |
| Feature availability depends on the Compose version | `watch` arrived in Compose 2.22, and `sync+restart` and `sync+exec` came later. Run `docker compose version` if an action is rejected. |
| Rebuilds are not instant | A `rebuild` runs an image build, so keep the Dockerfile layers ordered to reuse the cache. |
Exercise
Your service uses image: node:20 with no build section, and develop.watch is defined. Running docker compose watch does not update the container. What is wrong, and what is the minimum fix?
Show answer
Compose Watch can only manage services it builds. Add a build section (with a Dockerfile that copies the code into the image) so the sync and rebuild actions have an image layout to work with. Then run docker compose watch again.
Exercise
A rule has path: ./src and ignore: - src/cache/. Files in ./src/cache still sync. Why, and how do you fix it?
Show answer
ignore patterns are relative to path, so src/cache/ looks for ./src/src/cache/. Change the pattern to cache/.