600 words
3 min read

Docker Compose watch: Sync or Rebuild on Save, No Bind-Mount Surprises

By · Docker Captain · CNCF Ambassador · IBM Champion
Cover image for the post 'Transforming Development with Docker Compose Watch'

Building containers during dev is slow. Slow and repetitive. And it wastes a stupid amount of time, because you end up rebuilding the entire image over a three-line edit in index.js.

Docker Compose Watch fixes that. It’s not some half-baked beta toy either. It does the job.

You change a file, Docker reacts. Instantly. Your app syncs or rebuilds automatically, and you never type docker-compose up --build again just because you renamed a function.

So here’s how it works, plus why I rate it as the best thing to land in local Docker dev since bind mounts.

What Is watch in Docker Compose?#

It’s a feature, generally available since Compose 2.22, that points Docker Compose at your local files and lets it do two things:

  • Sync them into running containers (great for JS, Python, anything with hot reload)
  • Rebuild the container when certain files change (like package.json, requirements.txt, etc.)

So it’s file-watching with intent. Not dumb mirroring. Every update is targeted and rule-driven, which is the whole point.

Sync vs Rebuild: Know the Difference#

Two actions live in your compose.yaml. Here they are.

sync#

- action: sync
path: ./web
target: /src/web
ignore:
- node_modules/
  • Copies host changes into the container on save
  • Doesn’t restart or rebuild the container
  • Perfect for JS/TS/React/Flask/Django/Express/etc.

Treat it as a cleaner, tighter replacement for bind mounts.

rebuild#

- action: rebuild
path: package.json
  • Triggers a full image rebuild when the watched file changes
  • Same as doing docker compose up --build <svc> behind the scenes
  • Ideal for dependency files or compiled languages

Use both. Rebuild on config changes. Sync everything else.

How to Use Docker Compose Watch#

The full loop is short:

  1. Add a develop.watch section to your compose.yaml

  2. Start services with:

    Terminal window
    docker compose up --build --wait
  3. Run:

    Terminal window
    docker compose watch

Now your app updates in real time. That’s how development should feel.

Real Example: Node.js App with Hot Reload#

Say your project looks like this:

myproject/
├── web/
│ ├── App.jsx
│ └── index.js
├── Dockerfile
├── compose.yaml
└── package.json

Your compose.yaml:

services:
web:
build: .
command: npm start
develop:
watch:
- action: sync
path: ./web
target: /src/web
ignore:
- node_modules/
- action: rebuild
path: package.json

Start the service:

Terminal window
docker compose up --build --wait
docker compose watch

Now edit App.jsx, save, and refresh the browser. Done.

Test It Yourself: Run a Live Demo#

Clone the official demo:

Terminal window
git clone https://github.com/dockersamples/avatars.git
cd avatars
docker compose up -d
docker compose watch

Then hit:

http://localhost:5735

Change something in src/ and watch it reload while you look at it.

Pro Tips#

1. Use Sync for Hot Reload, Rebuild for State Changes#

Example:

  • Sync: ./src, ./templates, .env
  • Rebuild: Dockerfile, package.json, requirements.txt

2. Ignore What Doesn’t Matter#

ignore:
- node_modules/
- dist/
- "*.log"

Otherwise every temp file you touch kicks off a sync. You don’t want that.

3. Optimize Your Dockerfile#

Lean on multi-stage builds and cache your layers properly:

COPY package.json .
RUN npm ci
COPY . .

Copy too early and Docker throws out the cache on every change.

Not Just for Node.js#

watch works far beyond Node. A few examples:

  • Python/Flask → sync .py, rebuild on requirements.txt
  • Go → rebuild on .go, mount volume for go run
  • Java/Spring → rebuild on .java or pom.xml
  • Rust → rebuild on Cargo.toml, cache your target dir

It’s universal. The only real question is how you structure your watches.

Bonus: No More Bind Mount Weirdness#

Bind mounts are fine, right up until they aren’t. You hit OS quirks. You fight permissions. And on Windows, performance just falls off a cliff.

Sync rules hand you precision. Rebuild triggers hand you control. No quirks attached.

TL;DR#

  • docker compose watch = auto-sync + auto-rebuild
  • Use sync for live reload workflows
  • Use rebuild for dependency changes or compiled code
  • Clean alternative to bind mounts
  • Works with any language, any stack

Final Take#

Dev loops should be fast. Not “wait 10 seconds for a container” fast. Save-and-see-it-immediately fast.

That’s what Docker Compose Watch buys you. It’s not production magic. It’s dev-experience magic, and it holds up.

You write code. Docker handles the rest.


Vladimir Mikhalev

Docker Captain  ·  CNCF Ambassador  ·  IBM Champion

The Verdict — production-tested analysis on YouTube.

The Verdict

Inconvenient truths about shipping in the AI era

Container security, platform engineering, and the agentic shift — tested in production, argued without the hype. The verdict reaches your inbox the moment there's one worth sending.

Related Posts

Same category
  1. 1
    A Partial Read Is Not a Smaller Fleet: A GitHub API Rate Limit and the Numbers That Lied for an Hour
    DevOps & Cloud · A partial read published as the whole. For an hour the profile said 24 restore scripts across 15 repositories, and the fleet had 73 across 48. Three guards now.
  2. 2
    Restore Drills on a Clean Machine — Measured RTO for 47 Stacks, 19 Seconds to 7 Minutes
    DevOps & Cloud · Restore drills that measure RTO on a machine that never ran the stack, 47 templates weekly. Every same-host restore passed. The first clean one answered 500.
  3. 3
    Mutation Testing for Infrastructure Code — 153 Planted Bugs, Four Tests That Could Not Fail
    DevOps & Cloud · Mutation testing for infrastructure code, done by hand across fifteen repositories. 153 planted bugs, and four green tests that could never have failed.
  4. 4
    Docker Health Checks That Cannot Fail — Seventeen Hours Green
    DevOps & Cloud · A Docker health check whose pattern matches the shell running it can never go red. How to find the checks in your fleet that never failed, and prove each one.

Random Posts

Random
  1. 1
    The End of the Executor — Why Computer Vision Engineers Are Becoming Optional
    Opinion & Culture · Anisoptera's Dragonfly platform proved specialized CV engineers are replaceable. The math ($150k vs $5k) and the blueprint to survive the shift.
  2. 2
    Install Exchange Server 2013
    SysAdmin & IT Pro · Step-by-step guide to install Exchange Server 2013 on Windows Server 2012 R2, including prerequisites, AD preparation, and full installation walkthrough.
  3. 3
    Install Kubernetes on Ubuntu Server 22.04 LTS
    DevOps & Cloud · Step-by-step guide to install Kubernetes on Ubuntu Server 22.04 LTS using kubeadm. Learn how to set up master and worker nodes with containerd and Calico.
  4. 4
    Install Wiki.js with Docker Compose
    Self-Hosting · Step-by-step guide to install Wiki.js with Docker Compose on Ubuntu using Traefik, Let's Encrypt, and PostgreSQL. Secure setup with SSH and HTTPS.
Docker Compose watch: Sync or Rebuild on Save, No Bind-Mount Surprises
https://heyvaldemar.com/transforming-development-with-docker-compose-watch/
Author
Vladimir Mikhalev
Published
2023-06-15
Updated
2026-11-05
License
CC BY-NC-SA 4.0