Skip to content

fix(watch): exclude Dockerfile and compose files from the sync loop - #14217

Open
Orivital wants to merge 2 commits into
docker:mainfrom
Orivital:fix/watch-exclude-compose-files-from-sync-loop
Open

Orivital wants to merge 2 commits into
docker:mainfrom
Orivital:fix/watch-exclude-compose-files-from-sync-loop

Conversation

@Orivital

@Orivital Orivital commented Sep 12, 2026

Copy link
Copy Markdown

What I did

#14117 restored the initialSync exclusion so docker compose watch does not copy the Dockerfile or compose files into the container on first sync. That PR called out that the continuous loop (getWatchRules) never had the same ignore, and that it would need a differently-anchored matcher because it matches absolute host paths rather than basenames.

Without that, a develop.watch sync on the project root still copies Dockerfile / compose.yaml (and a custom build.dockerfile) into the container when those files change after watch has started.

Shared the ignore as dockerFileIgnoreMatcher with **/-anchored patterns so it works for both initialSync's basenames and the watch loop's full paths. Applied it only to copy actions (sync, sync+restart, sync+exec) so a rebuild trigger on the same tree still fires when those files change.

Test plan

  • Unit: go test ./pkg/compose/ -run 'TestGetWatchRules|TestInitialSync'
  • Repro with released docker compose watch on a root sync to /work: editing Dockerfile after start copies it into the container
  • Same steps with this binary: /work stays empty
  • Existing TestWatch* e2e cases do not cover this path; the full e2e suite was not run

Related issue
N/A

initialSync already skipped these after docker#14117, but getWatchRules never
did. A later edit was still copied into the container. Anchor the shared
ignore with **/ so it matches the watch loop's absolute paths, and apply
it only to copy actions so rebuild still fires.

Signed-off-by: orivital <orivital2924@gmail.com>
@Orivital
Orivital requested review from a team as code owners September 12, 2026 13:09
@Orivital
Orivital requested review from glours and ndeloof September 12, 2026 13:10
Comment thread pkg/compose/watch.go Outdated
// **/anchored so the matcher hits both initialSync's basenames and the
// watch loop's absolute host paths.
func dockerFileIgnoreMatcher(service types.ServiceConfig) (watch.PathMatcher, error) {
names := append([]string{"Dockerfile"}, cli.DefaultFileNames...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should only select service.Build.Dockerfile.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. The watch matcher now only uses service.Build.Dockerfile (or Dockerfile when that's empty). Compose files are still skipped on initialSync, same as #14117.
fe986b5

Default compose filenames and an unused Dockerfile stay eligible for
sync. initialSync still excludes compose files.

Signed-off-by: orivital <orivital2924@gmail.com>
@Orivital
Orivital force-pushed the fix/watch-exclude-compose-files-from-sync-loop branch from 8940757 to fe986b5 Compare September 15, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants