Day 35advancedMar 7, 2026

Hot-Reload Containers in Dev with Docker Compose Watch

Stop manually rebuilding containers every time you change a file — let Compose Watch do it for you.

dockerdocker-composedevelopment
Share:

What

Docker Compose Watch automatically detects file changes on your host and either syncs them into the running container or triggers a rebuild. It replaces clunky volume mounts with a purpose-built dev workflow that supports sync, rebuild, and sync+restart actions. Requires Docker Compose v2.22.0+ (included in Docker Desktop 4.24+).

Why It Matters

Traditional volume mounts have filesystem compatibility issues across platforms, don't trigger rebuilds when dependencies change, and can expose your entire project directory. Compose Watch gives you fine-grained control over what happens when specific files change, making container-based development feel as fast as local development.

Example

# compose.yaml
services:
  web:
    build: .
    ports:
      - "3000:3000"
    develop:
      watch:
        # Sync source files without rebuild
        - action: sync
          path: ./src
          target: /app/src
        # Rebuild when dependencies change
        - action: rebuild
          path: ./package.json
        # Sync config and restart the container
        - action: sync+restart
          path: ./config
          target: /app/config

# Start with watch mode
# docker compose watch
dockerfile

Common Mistake

Using Compose Watch for production deployments. Watch mode is a development-only feature that actively monitors your filesystem. In production, use proper CI/CD pipelines to build and deploy immutable images.

Quick Fix

Use 'sync' for source code changes (hot-reload), 'rebuild' for dependency file changes (package.json, requirements.txt), and 'sync+restart' for config files that need a process restart to take effect.

Key Takeaways

  • 1docker compose watch = auto-sync + rebuild
  • 2sync: hot-reload source files into container
  • 3rebuild: trigger full rebuild on dependency changes
  • 4sync+restart: sync files and restart process
  • 5Development only — never use in production

Was this tip helpful?

Help us improve the DevOpsPath daily collection

Share: