🐳 Docker Advanced

What is Compose watch and how does it improve developer experience?

Answer

Docker Compose Watch (introduced in Docker Compose 2.22 / Docker Desktop 4.24) is a developer experience feature that automatically syncs file changes from the host into running containers and can trigger service rebuilds — providing a live development loop without manually restarting services. Configure in compose.yml under each service: develop:\n watch:\n - action: sync\n path: ./src\n target: /app/src\n - action: rebuild\n path: ./package.json\n - action: sync+restart\n path: ./config\n target: /app/config. Actions: sync — copy changed files into the running container (like a live bind mount but more targeted); rebuild — trigger a docker compose build + recreate when specified files change (e.g., package.json changes → rebuild image with new dependencies); sync+restart — sync files then restart the container. Start with watch: docker compose watch (or docker compose up --watch). Benefits over bind mounts: (1) Works correctly on macOS (bind mounts on Mac suffer from performance and inotify issues); (2) More explicit control over what gets synced; (3) Can trigger rebuilds for dependency changes without syncing node_modules back; (4) Compatible with native file watchers in frameworks (nodemon, webpack HMR). Requires Docker Compose spec v2+ and BuildKit.