{"record":{"id":"fd60ca8c09c9dee4","repo":"docker/cli","slug":"no-such-service-service","errorCode":null,"errorMessage":"no such service: {service}","messagePattern":"no such service: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/service/ps.go","lineNumber":80,"sourceCode":"\t}\n\n\ttasks, err := apiClient.TaskList(ctx, client.TaskListOptions{Filters: filter})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tformat := options.format\n\tif len(format) == 0 {\n\t\tformat = task.DefaultFormat(dockerCli.ConfigFile(), options.quiet)\n\t}\n\tif options.quiet {\n\t\toptions.noTrunc = true\n\t}\n\tif err := task.Print(ctx, dockerCli, tasks, idresolver.New(apiClient, options.noResolve), !options.noTrunc, options.quiet, format); err != nil {\n\t\treturn err\n\t}\n\tif len(notfound) != 0 {\n\t\treturn errors.New(strings.Join(notfound, \"\\n\"))\n\t}\n\treturn nil\n}\n\nfunc createFilter(ctx context.Context, apiClient client.APIClient, options psOptions) (client.Filters, []string, error) {\n\tfilter := options.filter.Value()\n\n\tserviceIDFilter := make(client.Filters)\n\tserviceNameFilter := make(client.Filters)\n\tfor _, service := range options.services {\n\t\tserviceIDFilter.Add(\"id\", service)\n\t\tserviceNameFilter.Add(\"name\", service)\n\t}\n\tserviceByID, err := apiClient.ServiceList(ctx, client.ServiceListOptions{Filters: serviceIDFilter})\n\tif err != nil {\n\t\treturn filter, nil, err\n\t}\n\tserviceByName, err := apiClient.ServiceList(ctx, client.ServiceListOptions{Filters: serviceNameFilter})","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/service/ps.go#L62-L98","documentation":"In `runPS()` (ps.go:79-81), after successfully listing and printing tasks for the services that WERE found, the function checks if the `notfound` slice is non-empty and returns the joined error strings. This path is reached from `createFilter()` which returns `(filter, notfound, nil)` when at least one service matched (`serviceCount > 0`) but one or more did not. The error message format is `\"no such service: <input>\"` per missing service (constructed at line 134), joined with newlines if multiple. Tasks for the found services are still printed before the error is returned.","triggerScenarios":"Running `docker service ps myservice nonexistent-service` where `myservice` exists but `nonexistent-service` does not. The tasks for `myservice` are listed, then the error for `nonexistent-service` is returned with exit code 1. Also triggered by a partial ID prefix match that doesn't resolve to any service.","commonSituations":"A script passes a list of service names/IDs where one has a typo or was deleted. The operator sees tasks for found services but also gets the error.","solutions":["Verify each service name/ID exists before passing it: `docker service ls --filter name=<name>`","Remove the non-existent service reference from the command arguments","Use full service IDs instead of prefixes to avoid ambiguity and not-found issues"],"exampleFix":"# before\ndocker service ps web-service typo-service\n# (tasks for web-service shown, then error: no such service: typo-service)\n\n# after\ndocker service ps web-service\n\n# or verify first\ndocker service ls --filter name=typo-service","handlingStrategy":"validation","validationCode":"// Before calling runPS, verify all services exist\nfunc validateServicesExist(ctx context.Context, c client.APIClient, services []string) ([]string, error) {\n    var missing []string\n    for _, svc := range services {\n        _, err := c.ServiceInspect(ctx, svc, client.ServiceInspectOptions{})\n        if errdefs.IsNotFound(err) {\n            missing = append(missing, svc)\n        }\n    }\n    if len(missing) > 0 {\n        return missing, fmt.Errorf(\"services not found: %s\", strings.Join(missing, \", \"))\n    }\n    return nil, nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-validate all service names/IDs with `docker service ls` before batch ps operations","Use full service names to avoid prefix-resolution failures","In scripts, separate existing and non-existing services to avoid partial-success confusion"],"tags":["docker","cli","service","ps","not-found"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}