Transforming Development with Docker Compose Watch
By Vladimir Mikhalev · Solutions Architect · Docker Captain · IBM Champion
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, still in alpha, 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:
-
Add a
x-develop.watchsection to yourcompose.yaml -
Start services with:
Terminal window docker compose up --build --wait -
Run:
Terminal window docker compose alpha 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.jsonYour compose.yaml:
services: web: build: . command: npm start x-develop: watch: - action: sync path: ./web target: /src/web ignore: - node_modules/ - action: rebuild path: package.jsonStart the service:
docker compose up --build --waitdocker compose alpha watchNow edit App.jsx, save, and refresh the browser. Done.
Test It Yourself: Run a Live Demo
Clone the official demo:
git clone https://github.com/dockersamples/avatars.gitcd avatarsdocker compose up -ddocker compose alpha watchThen hit:
http://localhost:5735Change 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/ - *.logOtherwise 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 ciCOPY . .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 onrequirements.txt - Go → rebuild on
.go, mount volume forgo run - Java/Spring → rebuild on
.javaorpom.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 alpha watch= auto-sync + auto-rebuild- Use
syncfor live reload workflows - Use
rebuildfor 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.
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
- 1Terraform MCP server GA: the Apply Gate your auditor will ask aboutDevOps & Cloud · HashiCorp's Terraform MCP server is GA and IBM Bob can write production IaC. ENABLE_TF_OPERATIONS separates a safe assistant from autonomous apply.
- 2Docker supply chain hardening — from Scout D to OpenSSF 7.8 on a 730K-pull imageDevOps & Cloud · How I hardened a 730K-pull public Docker image from Scout grade D to OpenSSF Scorecard 7.8. Multi-stage build, cosign signing, SLSA provenance, non-root default, and the incident that changed how I ship attestations.
- 3Cloudflare Web Analytics on Astro — Why Removing GA4 Unlocked Lighthouse 100DevOps & Cloud · How removing Google Analytics 4 from an Astro site unlocked Lighthouse 100, why Cloudflare Web Analytics replaced it, and what the tradeoffs actually cost.
- 4Platform Engineering — The Complete, Practical Guide to Building Internal Developer Platforms That ScaleDevOps & Cloud · A deep, practical guide to Platform Engineering. Learn how to build internal developer platforms, golden paths, GitOps workflows, and scalable cloud foundations.
Random Posts
- 1Install ServiceDesk Plus on Ubuntu ServerSysAdmin & IT Pro · Comprehensive guide to installing ServiceDesk Plus on Ubuntu Server 22.04 LTS. Covers setup, port config, auto-start service, and admin login.
- 2Top 10 DevOps Tools for 2025 — Must-Have for Developers and EngineersDevOps & Cloud · Explore the top 10 DevOps tools for 2025 to optimize workflows, enhance security, and streamline CI/CD, GitOps, and Kubernetes.
- 3Inside the Builders Era — How Developers Stay in Control of AI with GitKraken as the Core ToolOpinion & Culture · How developers stay in control of AI in the Builders Era — using expert supervision, clean Git workflows, and GitKraken to keep speed, quality, and reliability.
- 4Machine Learning and Deep Learning Courses on YouTubeAI & MLOps · Explore the best free YouTube courses in machine learning and deep learning—from beginner-friendly foundations to advanced topics like NLP, CV, and MLOps.