{"record":{"id":"baee40cf7e6d12f0","repo":"docker/compose","slug":"can-t-watch-service-q-with-action-s-without-a-bu","errorCode":null,"errorMessage":"can't watch service %q with action %s without a build context","messagePattern":"can't watch service %q with action (.+?) without a build context","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compose/watch.go","lineNumber":221,"sourceCode":"\t)\n\tfor serviceName, service := range project.Services {\n\t\tconfig, err := loadDevelopmentConfig(service, project)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif service.Develop != nil {\n\t\t\tconfig = service.Develop\n\t\t}\n\n\t\tif config == nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, trigger := range config.Watch {\n\t\t\tif trigger.Action == types.WatchActionRebuild {\n\t\t\t\tif service.Build == nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"can't watch service %q with action %s without a build context\", service.Name, types.WatchActionRebuild)\n\t\t\t\t}\n\t\t\t\tif options.Build == nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"--no-build is incompatible with watch action %s in service %s\", types.WatchActionRebuild, service.Name)\n\t\t\t\t}\n\t\t\t\t// set the service to always be built - watch triggers `Up()` when it receives a rebuild event\n\t\t\t\tservice.PullPolicy = types.PullPolicyBuild\n\t\t\t\tproject.Services[serviceName] = service\n\t\t\t}\n\t\t}\n\n\t\tfor _, trigger := range config.Watch {\n\t\t\tif isSync(trigger) && checkIfPathAlreadyBindMounted(trigger.Path, service.Volumes) {\n\t\t\t\tlogrus.Warnf(\"path '%s' also declared by a bind mount volume, this path won't be monitored!\\n\", trigger.Path)\n\t\t\t\tcontinue\n\t\t\t} else {\n\t\t\t\tshouldInitialSync := trigger.InitialSync\n\n\t\t\t\t// Check legacy extension attribute for backward compatibility","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/watch.go#L203-L239","documentation":"While collecting watch rules, compose validates each trigger: a rebuild action requires the service to be built from source, because rebuild re-runs the build. If the service has no build: section (image-only), watch cannot rebuild it and fails naming the service and action.","triggerScenarios":"Configuring develop.watch with action: rebuild on a service that specifies only image: (no build context). Starting watch then fails during rule construction.","commonSituations":"Copy-pasting a watch block from a build-based service onto an image-based one; switching a service from build to a prebuilt image but leaving its develop.watch rebuild rule in place.","solutions":["Remove the rebuild watch trigger from the image-only service, or change its action to sync or sync+restart.","Add a build: section (context/dockerfile) to the service if rebuild-on-change is intended.","Split long-lived source watching into a separate build-based compose service."],"exampleFix":"# before\nservices:\n  api:\n    image: registry.example.com/team/api:1.0   # no build:\n    develop:\n      watch:\n        - action: rebuild\n          path: ./src\n\n# after\nservices:\n  api:\n    image: registry.example.com/team/api:1.0\n    develop:\n      watch:\n        - action: sync\n          path: ./src\n          target: /app/src","handlingStrategy":"validation","validationCode":"func rebuildTriggersBackedByBuild(project *types.Project) error {\n\tfor name, svc := range project.Services {\n\t\tif svc.Develop == nil { continue }\n\t\tfor _, t := range svc.Develop.Watch {\n\t\t\tif t.Action == types.WatchActionRebuild && svc.Build == nil {\n\t\t\t\treturn fmt.Errorf(\"service %q has rebuild watch but no build section\", name)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := composeService.Watch(ctx, projectName, opts); err != nil {\n    if strings.Contains(err.Error(), \"without a build context\") {\n        // change the trigger action to sync/sync+restart or add build: to the service\n    }\n    return err\n}","preventionTips":["Use rebuild actions only on services with a build: section.","When converting a service to a prebuilt image, prune its develop.watch rebuild rules.","Lint develop.watch actions against service.build presence in CI."],"tags":["compose","watch","rebuild","build-context"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}