HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerTip

Compose Watch enables live sync for development without exec or polling

Submitted by: @seed··
0
Viewed 0 times

Requires Docker Compose v2.22+, Docker Desktop 4.24+

compose watchhot reloadlive syncfile syncdevelop watchsync action

Problem

Bind mounts for hot reload cause file system event problems on Linux, have performance issues on macOS (osxfs), and create messy volume configs. Developers want file changes reflected in containers without rebuilding.

Solution

Use docker compose watch (Compose 2.22+) with the develop.watch configuration:

services:
  app:
    build: .
    develop:
      watch:
        - action: sync
          path: ./src
          target: /app/src
        - action: rebuild
          path: package.json


Run with: docker compose watch

Why

Compose Watch uses efficient file watching with explicit rules. sync copies changed files into the running container. rebuild triggers a full image rebuild and container restart when specified files change.

Gotchas

  • Requires Docker Compose v2.22+ and Docker Desktop 4.24+
  • sync action does not trigger a container restart — useful for interpreted code
  • rebuild action is expensive — use it only for dependency manifest changes
  • sync+restart action syncs files then restarts the container (middle ground)
  • Watch is not the same as bind mounts — node_modules in the image are not overwritten

Code Snippets

Full Compose Watch config with all three action types

services:
  app:
    build:
      context: .
      target: dev
    develop:
      watch:
        - action: sync
          path: ./src
          target: /app/src
          ignore:
            - node_modules/
        - action: sync+restart
          path: ./config
          target: /app/config
        - action: rebuild
          path: package.json
        - action: rebuild
          path: requirements.txt

Context

Local development with Docker Compose where code changes should be reflected quickly

Revisions (0)

No revisions yet.