docker/compose · error

--no-build is incompatible with watch action %s in service %

Error message

--no-build is incompatible with watch action %s in service %s

What it means

A rebuild watch trigger requires compose to be allowed to build. When watch is invoked with options.Build == nil (the --no-build flag), the incompatibility is detected while building watch rules and fails with this error naming the service.

Source

Thrown at pkg/compose/watch.go:224

		if err != nil {
			return nil, err
		}

		if service.Develop != nil {
			config = service.Develop
		}

		if config == nil {
			continue
		}

		for _, trigger := range config.Watch {
			if trigger.Action == types.WatchActionRebuild {
				if service.Build == nil {
					return nil, fmt.Errorf("can't watch service %q with action %s without a build context", service.Name, types.WatchActionRebuild)
				}
				if options.Build == nil {
					return nil, fmt.Errorf("--no-build is incompatible with watch action %s in service %s", types.WatchActionRebuild, service.Name)
				}
				// set the service to always be built - watch triggers `Up()` when it receives a rebuild event
				service.PullPolicy = types.PullPolicyBuild
				project.Services[serviceName] = service
			}
		}

		for _, trigger := range config.Watch {
			if isSync(trigger) && checkIfPathAlreadyBindMounted(trigger.Path, service.Volumes) {
				logrus.Warnf("path '%s' also declared by a bind mount volume, this path won't be monitored!\n", trigger.Path)
				continue
			} else {
				shouldInitialSync := trigger.InitialSync

				// Check legacy extension attribute for backward compatibility
				if !shouldInitialSync {
					var legacyInitialSync bool
					success, err := trigger.Extensions.Get("x-initialSync", &legacyInitialSync)

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Drop --no-build from the watch invocation so rebuild triggers can build.
  2. Or remove/replace the rebuild triggers in the develop.watch config of the named service with sync or sync+restart.
  3. Scope the watch command to services without rebuild triggers if --no-build must stay.

Example fix

# before
$ docker compose watch --no-build
# Error: --no-build is incompatible with watch action rebuild in service web

# after
$ docker compose watch
Defensive patterns

Strategy: validation

Validate before calling

func watchOptionsConsistent(project *types.Project, hasBuildOpt bool) error {
	for name, svc := range project.Services {
		if svc.Develop == nil { continue }
		for _, t := range svc.Develop.Watch {
			if t.Action == types.WatchActionRebuild && !hasBuildOpt {
				return fmt.Errorf("cannot use --no-build: service %q rebuilds on watch", name)
			}
		}
	}
	return nil
}

Try / catch

if _, err := composeService.Watch(ctx, projectName, watchOpts); err != nil {
    if strings.Contains(err.Error(), "--no-build is incompatible") {
        // drop --no-build / unset the no-build option and retry
    }
    return err
}

Prevention

When it happens

Trigger: Running docker compose watch --no-build (or passing WatchOptions without Build) on a project where any selected service's develop.watch contains action: rebuild.

Common situations: CI or scripts reusing flags from up --no-build; users trying to prevent image builds during watch while keeping rebuild triggers; copy-pasted command lines.

Related errors


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/784ec8aa2cd3e860. Report an issue: GitHub.