If you develop with Docker Compose, you know the loop: edit code, rebuild the image, restart the container, wait, repeat. That cycle is slow, error-prone, and it breaks your flow exactly when you are trying to test a small change. Docker Compose Watch solves this by watching your files and automatically syncing, rebuilding, or restarting services when something changes. This guide explains how docker compose watch works, how to configure it, and how to use it in a real development workflow.

With docker compose watch enabled, Compose monitors the paths you declare and reacts the moment a file changes. A static file can be copied straight into the running container, a source file can trigger a rebuild, and a configuration change can restart the service. You stop running manual rebuild commands, and your container stays in step with your working tree without you thinking about it.
Prerequisites
Before you begin, make sure you have the following:
- Docker Engine 24 or newer with Compose V2 installed. Check with
docker compose version; watch support requires Compose 2.22 or later. - A project with a working
compose.yamlfile and a Dockerfile that already builds and runs. - A basic understanding of Compose services, volumes, and build contexts. If you use profiles to organise stacks, our guide on Docker Compose profiles for stacks is a useful companion.
- Your project source on a local filesystem where file change events are reliable. Watch works best on Linux and macOS; on some networked filesystems, events can be delayed.
Watch is a development feature, not a production deployment tool. Do not enable it on production servers, where changes should arrive through tested images and controlled rollouts instead.
How Docker Compose Watch Works
Docker Compose Watch adds a develop.watch section to a service in your Compose file. Each watch rule names a path to monitor and an action to take when that path changes. There are three actions:
- sync — copies changed files directly into the running container, without a rebuild. Ideal for static assets, templates, and interpreted code such as Python or Node.js scripts.
- rebuild — rebuilds the image and recreates the container. Use this when a change affects the build itself, such as dependencies, compiled code, or the Dockerfile.
- sync+restart — syncs the files and then restarts the container, for cases where the application reads files only at startup.
You start watching with docker compose watch instead of docker compose up. Compose builds and starts your services, then stays in the foreground printing what it syncs or rebuilds as you edit files.
Docker Compose Watch Configuration Step by Step
The example below is a small Node.js web service. It syncs source files instantly and rebuilds when the package manifest changes, because a dependency change needs a fresh image.
Step 1: Add a watch section to your Compose file
Edit compose.yaml and add develop.watch under your service:
services:
web:
build: .
ports:
- "3000:3000"
develop:
watch:
- action: sync
path: ./src
target: /app/src
- action: rebuild
path: ./package.json
- action: sync+restart
path: ./config
target: /app/config
For sync and sync+restart, target is the directory inside the container that receives the files. For rebuild, no target is needed, because the whole image is rebuilt from the build context.
Step 2: Ignore files that should not trigger actions
Without ignore rules, editor swap files, build output, and node_modules can cause noisy rebuild loops. Add an ignore list to each rule, or use a .dockerignore file to keep junk out of the build context:
services:
web:
build: .
develop:
watch:
- action: sync
path: ./src
target: /app/src
ignore:
- src/*.log
- src/**/*.tmp
Keep your ignore list tight. Every unnecessary rebuild costs time, and a rebuild loop triggered by generated files can make watch feel slower than the manual workflow it replaces.
Step 3: Start watching
From your project directory, run:
docker compose watch
Compose builds the image if needed, starts the service, and prints a watching banner. Now edit a file under ./src and save it. You should see a sync message within a second or two, and your application should reflect the change without any restart. Edit package.json and watch will rebuild the image instead.
To stop watching, press Ctrl+C. Compose stops the watched services, just as docker compose down would if you passed the same project name. If you prefer to keep containers running in the background while still watching, run docker compose up --watch, which starts services detached and attaches the watcher.
Step 4: Combine watch with rebuild and restart rules
Real projects usually need all three actions. A typical web service syncs templates and static files, restarts when server configuration changes, and rebuilds when dependencies or compiled assets change:
services:
api:
build: .
develop:
watch:
- action: sync
path: ./templates
target: /app/templates
- action: sync+restart
path: ./settings.yaml
target: /app/settings.yaml
- action: rebuild
path: ./requirements.txt
For a full reference on the available options, see the official Docker Compose file watch documentation. It documents the watch schema, ignore patterns, and behaviour when multiple rules match the same file.
Docker Compose Watch in a Daily Development Workflow
Once watch is running, your loop becomes: edit, save, check the browser or API response. There is no rebuild command to remember and no stale container serving yesterday’s code. That matters most for interpreted languages, where sync alone is enough, and for frontend assets, where a synced file is picked up by a dev server immediately.
For compiled languages such as Go or Rust, pair a rebuild rule for source files with a multi-stage Dockerfile that caches dependencies. The first rebuild is slow, but later rebuilds reuse cached layers, so only the compile step repeats. If rebuilds still feel slow, check that your .dockerignore excludes build output and test artefacts, since everything in the build context is sent to the daemon on every rebuild.
Watch also pairs well with Compose profiles. You can watch only the service you are actively developing while leaving databases and caches untouched, which keeps rebuilds fast and avoids restarting stateful services by accident.
Troubleshooting
Nothing happens when I save a file. Check that the path in your watch rule is relative to the Compose file location, and that the file is not excluded by an ignore rule or by your editor writing to a temporary file and renaming it. Save the file directly and check the watch output for a sync or rebuild line.
Watch rebuilds in a loop. A generated file inside a watched path is the usual cause, for example a build tool writing output back into ./src. Add that output path to ignore, or move generated files outside watched directories.
Sync succeeds but the app shows old code. Some frameworks cache templates or code in memory at startup. Use sync+restart for those paths, or enable the framework’s own reload mode so it re-reads synced files.
Watch fails with an old Compose version. Update Compose to 2.22 or later. Run docker compose version and upgrade Docker Desktop or the Compose plugin if the version is older.
File events are delayed on a mounted or network drive. Move the project to a local disk for development. Networked filesystems often batch or drop change notifications, which makes any file watcher unreliable.
Conclusion
Docker Compose Watch turns the tedious edit, rebuild, restart cycle into a background process you can forget about. Configure develop.watch with sync for files your app reads live, sync+restart for startup configuration, and rebuild for dependencies and compiled code, then start it with docker compose watch and let your editor drive the container. With sensible ignore rules and a clean build context, it is one of the simplest ways to make containerised development feel as fast as running code directly on your machine. Add it to your next Compose project and measure how many manual rebuilds it saves in a single day.