Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 94/ 160
05. Docker Compose & Multi-Container Apps

Live Development Workflows with docker compose watch (Sync & Rebuild)

Use compose watch to sync files and rebuild services during local development.

Intermediatewatch · Sync3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Use sync for interpreter/source files whose process can reload, and rebuild for compiled dependencies or Dockerfile/base changes.

Think of it like…

watch is a conveyor belt with two lanes: small editable drawings ride into the existing station, while a new machine part sends the whole station back through the workshop.

Where you’ve seen it

In practice, develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] } is the concrete move for this job: use compose watch to sync files and rebuild services during local development. The release is not accepted until run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events confirms the result.

Words you’ll hear

watch
The implementation control in develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] } for use compose watch to sync files and rebuild services during local development.
Sync
The result to observe with run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events, rather than infer from a successful command alone.
Rebuild
The production boundary exposed when declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild.

Visual diagram

Loading interactive diagram

Theory & deep dive

watch control path

The concrete mechanism is develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] }. The observable result is run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events; if those disagree, inspect the runtime evidence before changing unrelated settings.

Use compose watch to sync files and rebuild services during local development. Keep watch, Sync and Rebuild in the same deployment record so the intent and the observed state cannot drift apart.

Concrete watch setup

develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] }

Key takeaway: Prove Sync with run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events, not with command success alone.

Rebuild failure boundary

Syncing dependencies, locks or generated artifacts can leave an app in a mixed state. File system events through Docker Desktop/WSL mounts and process reload support differ, so watch needs an explicit action matrix and ignore list. The narrow failure to design for is declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild.

Accept this compromise explicitly: Watch shortens one-host development loops; a full rebuild remains the production fidelity test. The controlled check-run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild.

Key takeaway: Watch shortens one-host development loops; a full rebuild remains the production fidelity test.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: Syncing dependencies, locks or generated artifacts can leave an app in a mixed state. File system events through Docker Desktop/WSL mounts and process reload support differ, so watch needs an explicit action matrix and ignore list.

Use sync for interpreter/source files whose process can reload, and rebuild for compiled dependencies or Dockerfile/base changes.
Key numbers at this step
Intent
watch

When to use it & trade-offs

What it is

compose watch attaches development actions to services: sync copies changed files into a path in a container, rebuild runs a Docker build and replaces the image, and rebuild-or-sync can fall back when action or ignore rules change.

Why it matters: Syncing dependencies, locks or generated artifacts can leave an app in a mixed state. File system events through Docker Desktop/WSL mounts and process reload support differ, so watch needs an explicit action matrix and ignore list.

When to reach for it

  • The fit is strongest for this job: use compose watch to sync files and rebuild services during local development. Pair it with run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events in the runbook.
  • Production watch changes should make Sync observable through develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] }, rather than trusting the runtime default.
  • Keep a rollback example for the case where declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild.

When to avoid or be careful

  • Do not accept command success while the system can still fail by declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild.
  • Avoid erasing Rebuild protection merely to dodge this cost: “Watch shortens one-host development loops; a full rebuild remains the production fidelity test”.
  • Do not replace the evidence path-run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events-with a screenshot or a mutable tag.

develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] }: practical choices

Explicit watch
Best for: Use compose watch to sync files and rebuild services during local development, with a reviewed runbook.

Strengths: compose watch attaches development actions to services: sync copies changed files into a path in a container, rebuild runs a Docker build and replaces the image, and rebuild-or-sync can fall back when action or ignore rules change.

Watch out: Watch shortens one-host development loops; a full rebuild remains the production fidelity test.

Ambient default
Best for: Short-lived Sync experiments with low blast radius.

Strengths: It can begin with develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] } and fewer surrounding controls.

Watch out: It silently accepts declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild, which makes the result hard to reproduce after promotion.

Managed Rebuild
Best for: Teams that centralize Rebuild policy across many workloads.

Strengths: Syncing dependencies, locks or generated artifacts can leave an app in a mixed state. File system events through Docker Desktop/WSL mounts and process reload support differ, so watch needs an explicit action matrix and ignore list.

Watch out: The platform adds an ownership and debugging layer; retain run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events as the direct check.

Interview signals & numbers to know

When this topic comes up

  • develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] }
  • run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events
  • Failure signature: declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild
  • Trade-off: Watch shortens one-host development loops; a full rebuild remains the production fidelity test.

Benchmarks & rules of thumb

2 main actions -
sync and rebuild
1 process reload path -
required for synced code to become live
0 production promotion -
from a watch-only edit that never builds a release artifact

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] } as proof and skipping run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events.
  • Declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild
  • Optimizing watch without accepting that watch shortens one-host development loops; a full rebuild remains the production fidelity test.

Likely interviewer follow-ups

  • Why does develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] } address watch here rather than through application code?
  • How would you distinguish healthy Sync from the failure “declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild” using run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events?
  • When would this trade-off-“Watch shortens one-host development loops; a full rebuild remains the production fidelity test”-justify a different Rebuild design?
Interview tip: Give one concrete operation-develop: { watch: [{ action: sync, path: ./src, target: /app/src }, { action: rebuild, path: package-lock.json }] }-and one proof-run docker compose watch, change one source file and the lockfile separately, then observe sync versus rebuild events. Then name the boundary: declaring sync for native modules or lockfiles and expecting a different binary ABI to become valid without rebuild.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Live Development Workflows with docker compose watch (Sync & Rebuild) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Running One-Off Tasks & Migrations (docker compose run, exec)
Next topic
Resource Limits & Reservations in Compose (CPU & Memory)