{"record":{"id":"e109971dda19d9df","repo":"docker/cli","slug":"failed-to-create-service-s-w","errorCode":null,"errorMessage":"failed to create service %s: %w","messagePattern":"failed to create service (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/stack/deploy_composefile.go","lineNumber":294,"sourceCode":"\n\t\t\tfor _, warning := range response.Warnings {\n\t\t\t\t_, _ = fmt.Fprintln(dockerCLI.Err(), warning)\n\t\t\t}\n\n\t\t\tserviceIDs = append(serviceIDs, svc.ID)\n\t\t} else {\n\t\t\t_, _ = fmt.Fprintln(out, \"Creating service\", name)\n\n\t\t\t// query registry if flag disabling it was not set\n\t\t\tqueryRegistry := resolveImage == resolveImageAlways || resolveImage == resolveImageChanged\n\n\t\t\tresponse, err := apiClient.ServiceCreate(ctx, client.ServiceCreateOptions{\n\t\t\t\tSpec:                serviceSpec,\n\t\t\t\tEncodedRegistryAuth: encodedAuth,\n\t\t\t\tQueryRegistry:       queryRegistry,\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to create service %s: %w\", name, err)\n\t\t\t}\n\n\t\t\tserviceIDs = append(serviceIDs, response.ID)\n\t\t}\n\t}\n\n\treturn serviceIDs, nil\n}\n\nfunc waitOnServices(ctx context.Context, dockerCli command.Cli, serviceIDs []string, quiet bool) error {\n\tvar errs []error\n\tfor _, serviceID := range serviceIDs {\n\t\tif err := service.WaitOnService(ctx, dockerCli, serviceID, quiet); err != nil {\n\t\t\terrs = append(errs, fmt.Errorf(\"%s: %w\", serviceID, err))\n\t\t}\n\t}\n\treturn errors.Join(errs...)\n}","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/stack/deploy_composefile.go#L276-L312","documentation":"Raised by deployServices when creating a new service (not present in the stack namespace) and ServiceCreate fails. The wrapped %w carries the daemon error. This is the first-deploy path or the path for services newly added to the stack.","triggerScenarios":"First deploy of a stack, or adding a new service to an existing stack; ServiceCreate at deploy_composefile.go:288 returns an error (invalid spec, missing image, scheduling failure, name collision).","commonSituations":"Invalid or missing image; name collision with a service outside the stack; referencing non-existent networks/secrets/configs; resource constraints no node satisfies; manager unreachable or not a swarm node.","solutions":["Read the wrapped error for the daemon's rejection reason.","Ensure every service has a valid image and all referenced networks/secrets/configs are present.","Check `docker node ls` for available nodes matching any placement constraints.","Confirm the image exists and registry auth is correct (use --with-registry-auth).","Retry if the manager was temporarily unavailable."],"exampleFix":"// before: service missing an image (caught earlier) or invalid spec\nservices:\n  web:\n    build: .          # no image: for swarm deploy you must also set image\n// after: provide an image for swarm deploy\nservices:\n  web:\n    image: myregistry/web:latest\n    build: .","handlingStrategy":"validation","validationCode":"// Validate every service before deploy: image present, refs resolve, constraints satisfiable\nfor _, svc := range services {\n    if _, err := reference.ParseAnyReference(svc.Image); err != nil {\n        return fmt.Errorf(\"service %s invalid image: %w\", svc.Name, err)\n    }\n    if err := referencedSecretsAndConfigsExist(svc); err != nil { return err }\n    if !constraintsSatisfiable(svc.Placement, availableNodes) {\n        return fmt.Errorf(\"service %s placement unsatisfiable\", svc.Name)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure every service has a valid image and all referenced resources exist.","Provide --with-registry-auth when images are in private registries.","Confirm nodes satisfy placement constraints before first deploy."],"tags":["docker","stack","service","swarm","create","deploy"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}