Docker Compose — Compose Watch

1 minute read

docker compose watch (v2.22+) automatically syncs files and rebuilds when your code changes — no bind mounts needed.

Why Watch?

Feature Bind Mounts Compose Watch
File sync Immediate Immediate
Works with any FS Issues on some Consistent
Build steps Skipped Can trigger rebuild
Node modules Conflict risk Isolated

Configuration

services:
  api:
    build: ./api
    ports:
      - "3000:3000"
    develop:
      watch:
        - action: sync
          path: ./api/src
          target: /app/src

        - action: rebuild
          path: ./api/package.json

Watch Actions

Action Trigger Effect
sync File changed Copy file to container
rebuild File changed Rebuild image + recreate container
sync+restart File changed Copy file + restart container

Running Watch

docker compose watch

This starts all services and watches for changes. When you edit a file:

✔ api: Synced ./api/src/server.js to /app/src/server.js

Complete Example

services:
  api:
    build: ./api
    ports:
      - "3000:3000"
    develop:
      watch:
        - action: sync
          path: ./api/src
          target: /app/src
          ignore:
            - "**/*.test.js"

        - action: sync+restart
          path: ./api/config
          target: /app/config

        - action: rebuild
          path: ./api/package.json

  web:
    build: ./web
    ports:
      - "80:80"
    develop:
      watch:
        - action: sync
          path: ./web/src
          target: /app/src

        - action: rebuild
          path: ./web/package.json

Ignore Patterns

develop:
  watch:
    - action: sync
      path: ./src
      target: /app/src
      ignore:
        - "**/*.test.js"
        - "**/__tests__/**"
        - "**/node_modules/**"

Watch vs Bind Mounts

Bind Mount:
  Host FS ←→ Container FS (bidirectional)
  Fast but can have OS-specific issues

Compose Watch:
  Host FS → Container FS (one-way sync)
  Consistent across OS, supports rebuild triggers

Summary

Feature Detail
Command docker compose watch
Version Compose v2.22+
Actions sync, rebuild, sync+restart
Ignore Glob patterns for exclusion
Direction One-way (host → container)

Quick Reference

Item Detail
docker compose watch Start watching for changes
sync Copy changed files to container
rebuild Rebuild image on change
sync+restart Copy + restart container
ignore: Glob patterns to exclude
Version Compose v2.22+