{"record":{"id":"7af77ddd62f1f2ee","repo":"slimtoolkit/slim","slug":"cant-build-service-image-s","errorCode":null,"errorMessage":"cant build service image - %s","messagePattern":"cant build service image - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/compose/execution.go","lineNumber":625,"sourceCode":"\nfunc (ref *Execution) PrepareService(ctx context.Context, name string) error {\n\tref.logger.Debugf(\"Execution.PrepareService(%s)\", name)\n\tserviceInfo, ok := ref.AllServices[name]\n\tif !ok {\n\t\treturn fmt.Errorf(\"unknown service - %s\", name)\n\t}\n\n\tservice := serviceInfo.Config\n\tref.logger.Debugf(\"Execution.PrepareService(%s): image=%s\", name, service.Image)\n\n\tif service.Image == \"\" {\n\t\timageName := fmt.Sprintf(\"%s_%s\", ref.Project.Name, name)\n\t\tif ref.BuildImages && service.Build != nil {\n\t\t\tif err := buildImage(ctx, ref.apiClient, ref.BaseComposeDir, imageName, service.Build); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"cant build service image - %s\", name)\n\t\t}\n\t} else {\n\t\tfound, err := HasImage(ref.apiClient, service.Image)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif found {\n\t\t\treturn nil\n\t\t}\n\n\t\t//building image as if service.PullPolicy == types.PullPolicyBuild\n\t\t//todo: have an explicit flag for this behavior\n\t\tif ref.BuildImages && service.Build != nil {\n\t\t\tif err := buildImage(ctx, ref.apiClient, ref.BaseComposeDir, service.Image, service.Build); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/compose/execution.go#L607-L643","documentation":"In Execution.PrepareService, when the service config has no pre-built Image name, the execution computes an image name and builds it — but only if ref.BuildImages is enabled and service.Build is configured. If neither holds, it returns 'cant build service image - %s': the library cannot obtain an image for this service because building is disabled or the service has no build section.","triggerScenarios":"PrepareService on a service whose config has service.Image == \"\" while (a) ref.BuildImages is false (image building disabled for this execution), or (b) service.Build is nil (no build context defined in the compose file).","commonSituations":"Starting a compose project that uses `build:` sections with image building disabled (e.g. a pull-only/deployment mode), a compose service missing both `image:` and `build:` keys, or a typo'd build key that leaves service.Build nil.","solutions":["Add an `image:` field to the service in docker-compose.yml so a pre-built image can be used, and ensure that image exists locally or in the registry","Enable image building for the execution (set the BuildImages option / corresponding CLI flag) when services rely on `build:`","Ensure the service defines a valid `build:` section (context, dockerfile) so the builder can run"],"exampleFix":"// before (docker-compose.yml)\nservices:\n  worker:\n    # no image, no build -> cant build service image\n// after\nservices:\n  worker:\n    build:\n      context: ./worker\n    image: myapp/worker:latest","handlingStrategy":"validation","validationCode":"func canObtainImage(exec *compose.Execution, svc types.ServiceConfig) error {\n    if svc.Image != \"\" {\n        return nil\n    }\n    if !exec.BuildImages {\n        return fmt.Errorf(\"service %q has no image and building is disabled\", svc.Name)\n    }\n    if svc.Build == nil {\n        return fmt.Errorf(\"service %q has neither image nor build config\", svc.Name)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := execution.PrepareService(ctx, svc); err != nil {\n    if strings.HasPrefix(err.Error(), \"cant build service image\") {\n        return fmt.Errorf(\"cannot obtain image for %q: enable build or set image: %w\", svc, err)\n    }\n    return err\n}","preventionTips":["Give every service either an `image:` or a complete `build:` section","Enable the BuildImages option when any service relies on `build:`","Ensure build sections include a valid context and dockerfile","Pre-build and push images in CI so runtime doesn't depend on building"],"tags":["compose","docker","image-build"],"backgroundTag":"image-build-disabled","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}