Welcome to HowToShipIt — practical how-to guides for developers: code, AI tools, and servers, explained step by step.

Docker Compose Watch: Stop Rebuilding Containers Every Time You Save (2026)

You change one line of code, save, and then wait. You rebuild the image, restart the container, and by the time the app is back up you have forgotten what you were testing. If that loop sounds familiar, Docker Compose Watch is the feature you have been missing. It watches the files on your machine and pushes each change into the running container for you — syncing source code in milliseconds, rebuilding only when a dependency actually changes, and restarting the service only when a config file demands it. It has shipped in the Compose binary since version 2.22.0, so if you have updated Docker any time since late 2023, you already have it.

This guide sets up Docker Compose Watch from scratch: the three core actions, a working setup for Node.js, Python, and Laravel stacks, the two ways to run it, how it compares with bind mounts, and the seven mistakes that make people give up on it. Everything here was verified against the official Docker documentation on 17 November 2026.

What Docker Compose Watch Actually Does

Docker Compose Watch is a development feature, not a deployment strategy. You declare a develop.watch block inside a service in your compose.yaml, listing which host paths to monitor and what Compose should do when each one changes. Then you run docker compose up --watch instead of plain docker compose up. From that point on, every save triggers the cheapest correct action for that file — no manual rebuilds, no restarts you did not ask for.

It reached general availability in Compose 2.22.0, which shipped with Docker Desktop 4.24 in late 2023. The newer actions arrived later: sync+restart in 2.23.0, and restart and sync+exec in 2.32.0. Check your version first — anything older silently ignores the whole develop section, which is the single most common reason people conclude watch “does not work”.

docker compose version
# Docker Compose version v2.22.0 or newer — otherwise upgrade Docker Desktop
# or install the latest Compose plugin before continuing.

The Five Watch Actions, and When to Use Each One

Every watch rule pairs a path with one action. Picking the right action for each file type is the whole skill — get this wrong and you either rebuild constantly or wonder why your dependency change never took effect.

ActionWhat it doesUse it forNeeds
syncCopies the changed file into the running container. No restart, no rebuild.Source code in a framework with hot reload (Vite, Next.js, Flask debug mode)Compose 2.22+
rebuildRebuilds the image with BuildKit and recreates the container — the same as docker compose up --build.Dependency manifests and DockerfilesCompose 2.22+
sync+restartCopies the file, then restarts the container.Config files read once at startup (nginx.conf, .env, PHP-FPM config)Compose 2.23+
restartRestarts the container without syncing anything.Files already shared into the container by other meansCompose 2.32+
sync+execCopies the file, then runs a command inside the container.Running a linter, a test, or a code generator after each saveCompose 2.32+

The mental model is simple: sync for code, rebuild for dependencies, sync+restart for config. Everything else is a refinement of that rule.

Set Up Docker Compose Watch in 5 Minutes

Take a standard Node.js app. The Compose file needs two additions: a build section (watch only works on services built from local source — a service that only names a pre-built image is silently ignored) and a develop.watch block.

services:
  web:
    build: .
    command: npm run dev
    ports:
      - "3000:3000"
    develop:
      watch:
        # Source code: sync it in, Vite/Next.js hot reload does the rest.
        - action: sync
          path: ./src
          target: /app/src
          ignore:
            - node_modules/
        # Dependencies: a changed package.json needs a real rebuild.
        - action: rebuild
          path: package.json
        - action: rebuild
          path: package-lock.json

Start it with the watch flag and edit a file. The change lands in the container in well under a second, and your dev server’s hot reload picks it up exactly as if you had edited the file inside the container.

docker compose up --watch
# Edit src/App.jsx, save, and watch the output:
# Syncing service "web" after 1 change...
# Recreating... no, syncing only — the container keeps running.

The same pattern for Python and Laravel

The shape is identical across stacks — only the paths and the restart behaviour change. For a Flask or FastAPI app, sync the Python source and rebuild on requirements.txt:

services:
  api:
    build: .
    command: flask run --host=0.0.0.0 --reload
    develop:
      watch:
        - action: sync
          path: ./app
          target: /app/app
        - action: rebuild
          path: requirements.txt

For a Laravel app behind PHP-FPM, source code syncs fine, but config files are read once when the process starts — so they need sync+restart. The same applies to an Nginx service serving the app:

services:
  app:
    build: .
    develop:
      watch:
        - action: sync
          path: ./app
          target: /var/www/html/app
        - action: sync+restart
          path: ./.env
          target: /var/www/html/.env
  web:
    image: nginx:alpine
    develop:
      watch:
        - action: sync+restart
          path: ./docker/nginx/default.conf
          target: /etc/nginx/conf.d/default.conf

One warning on that last example: the web service uses a pre-built image, so its rebuild action would do nothing — but sync and sync+restart still work, because they only copy files and restart the container. The rule is that watch needs a build section only for the rebuild action; syncing works against any running container.

Two Ways to Run It: up –watch vs the watch Command

There are two entry points, and the difference is only about log noise. docker compose up --watch builds, starts, and watches in one foreground process, mixing application logs with rebuild and sync events. The dedicated docker compose watch command does the same job but keeps watch output separate from your app logs — useful when you already have a terminal tailing logs.

# Option 1: everything in one terminal
docker compose up --watch

# Option 2: watch in its own terminal, logs stay clean
docker compose up -d
docker compose watch

# Watch without starting anything (services already running elsewhere)
docker compose watch --no-up

# Hide the build output, show only watch events
docker compose watch --quiet

Two flags worth knowing: --no-up starts watching without building or starting services first, and --quiet hides build output so you see only sync and restart events. And one hard rule: watch never activates in detached mode. Running docker compose up -d --watch looks like it works — the flag is accepted — but Compose hands control back to your shell immediately, so nothing is watching. If your changes stop syncing for no apparent reason, check for a stray -d first.

One more housekeeping detail: every rebuild leaves the previous image dangling, and Compose prunes those automatically after each rebuild so you do not accumulate layers. Pass --prune=false if you want to keep the old images around for rollback.

Docker Compose Watch vs Bind Mounts: Which One Wins?

Most developers already use bind mounts for local development — ./src:/app/src in the volumes section. It works, but it has sharp edges, and watch was designed specifically to file them off.

Bind mountCompose Watch (sync)
DirectionTwo-way: container writes pollute your host treeOne-way: host to container only
DependenciesHost node_modules shadows the container’s (macOS build breaks the Linux app)Container keeps its own, built for Linux inside the image
Speed on macOS/WindowsSlow — every read crosses the Docker Desktop VM boundaryFast — files live natively in the container overlay filesystem
GranularityWhole directory, all or nothingPer-path rules with ignore patterns
Remote enginesImpossible — no shared filesystemWorks — Compose copies files over the connection
Editing from inside the containerWorksChanges are overwritten on the next host save

The practical rule of thumb, and the one the Docker community forums keep converging on: use watch for files you edit frequently, and volumes for data you need to persist. Source code gets a sync rule; Postgres data, Redis, and uploads get named volumes. Bind mounts still win for throwaway prototyping and for anything you genuinely need to edit from inside the container.

7 Mistakes That Make People Give Up on Watch

1. Syncing package.json instead of rebuilding on it

Sync only copies files. If you sync package.json, the file changes but node_modules inside the container does not — your new dependency is never installed and the app crashes on import. Dependency manifests always get rebuild. The same applies to requirements.txt, composer.json, and go.mod.

2. Running watch and a bind mount on the same path

If you mount ./src:/app/src and also configure watch to sync ./src to /app/src, the two mechanisms fight over the same files. Pick one per path. When you switch to watch, delete the source-code bind mount and keep only the named volumes for databases and caches.

3. Using -d with –watch

As above: docker compose up -d --watch never activates watch mode. Keep the process in the foreground, or run docker compose watch as a separate command after up -d.

4. Forgetting that ignore patterns are relative to the watched path

An ignore entry is relative to the path of its own rule, not to the project directory. With path: ./web, the ignore node_modules/ matches myproject/web/node_modules/. Get this wrong and your host’s node_modules gets synced over the container’s — the exact breakage watch exists to prevent. Note also that .dockerignore rules apply automatically, glob patterns are not supported in watch paths, and .git plus common editor temp files are ignored for you.

5. Putting watch on an image-only service and expecting rebuilds

Watch’s rebuild action needs a build section — there is no image to rebuild otherwise, and the rule is ignored. Sync and sync+restart still work on image-based services, but if you need rebuilds, the service must build from a local Dockerfile.

6. Editing compose.yaml and expecting watch to notice

Watch monitors the paths in your rules, not the Compose file itself. Changing compose.yaml — environment variables, ports, a new service — requires a normal restart with docker compose up. Watch is for code and config files, not for the stack definition.

7. Running it against production or staging

Watch holds a foreground process and copies unbuilt host files into containers. It has no place near a real deployment: no auth, no audit trail, and a stray save goes straight to a live service. Keep it on your laptop, and keep your production deploys on the proper image-based flow — the Docker deploy and multi-stage build guides on this blog cover that side.

Troubleshooting: When Changes Do Not Sync

Work through this list in order — it covers nearly every report of watch “not working” in the Docker forums.

  • “watch is not a recognized command” or the section is silently ignored. Your Compose is older than 2.22.0, or you are calling the legacy docker-compose Python script, which has no watch at all. Run docker compose version and upgrade.
  • Changes sync sometimes, then stop. You are editing across a filesystem boundary — Windows files against a WSL2 engine, or vice versa — and the file-change events are not crossing it. Keep the project inside the WSL filesystem (or the macOS home directory) rather than on a mounted Windows drive.
  • Sync runs but the app serves the old code. The container is running stale files with no error in the logs — the classic silent-staleness failure. Check that your target actually matches where the app reads from, and that the ignore patterns did not accidentally exclude the file you edited.
  • Permission errors on sync. Watch needs stat, mkdir, and rmdir inside the image, and the container’s USER must be able to write to the target path. If your Dockerfile copies files in as root, add COPY --chown=<user> so the service user owns them.
  • The container rebuilds on every save. A dependency file is in a sync rule’s path, or your editor writes a temp file that matches a rebuild rule. Narrow the watched path to the source directory and add explicit ignores for editor temp files and build output.

The Workflow That Actually Sticks

Start small. Add watch to one service — the frontend or the API you edit most — with a sync rule for its source and a rebuild rule for its manifest. Run docker compose up --watch for a day. Once you trust it, extend the same pattern across the stack: sync for code, rebuild for dependencies, sync+restart for config, named volumes for data, and no bind mounts left on source paths.

The payoff is not dramatic — it is the absence of drama. No more rebuild-then-wait loops, no more host node_modules breaking a Linux container, no more wondering whether the container is running the code you just saved. For a feature that has been sitting in your Compose binary since 2023, that is a lot of free productivity to leave on the table.

Verified against the official Docker documentation on 17 November 2026. Docker Compose Watch requires Compose 2.22.0 or later; sync+restart needs 2.23.0+, and restart / sync+exec need 2.32.0+.

Further Reading & References

Leave a Comment