{"record":{"id":"9f511352098c6eb9","repo":"docker/cli","slug":"multiple-services-found-with-provided-prefix-ser","errorCode":null,"errorMessage":"multiple services found with provided prefix: {service}","messagePattern":"multiple services found with provided prefix: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/service/ps.go","lineNumber":126,"sourceCode":"\t\tfor _, s := range serviceByID.Items {\n\t\t\tif s.ID == service {\n\t\t\t\tfilter.Add(\"service\", s.ID)\n\t\t\t\tserviceCount++\n\t\t\t\tcontinue loop\n\t\t\t}\n\t\t}\n\t\tfor _, s := range serviceByName.Items {\n\t\t\tif s.Spec.Annotations.Name == service {\n\t\t\t\tfilter.Add(\"service\", s.ID)\n\t\t\t\tserviceCount++\n\t\t\t\tcontinue loop\n\t\t\t}\n\t\t}\n\t\tfound := false\n\t\tfor _, s := range serviceByID.Items {\n\t\t\tif strings.HasPrefix(s.ID, service) {\n\t\t\t\tif found {\n\t\t\t\t\treturn filter, nil, errors.New(\"multiple services found with provided prefix: \" + service)\n\t\t\t\t}\n\t\t\t\tfilter.Add(\"service\", s.ID)\n\t\t\t\tserviceCount++\n\t\t\t\tfound = true\n\t\t\t}\n\t\t}\n\t\tif !found {\n\t\t\tnotfound = append(notfound, \"no such service: \"+service)\n\t\t}\n\t}\n\tif serviceCount == 0 {\n\t\treturn filter, nil, errors.New(strings.Join(notfound, \"\\n\"))\n\t}\n\treturn filter, notfound, err\n}\n\nfunc updateNodeFilter(ctx context.Context, apiClient client.APIClient, filter client.Filters) error {\n\tif nodeFilters, ok := filter[\"node\"]; ok {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/service/ps.go#L108-L144","documentation":"In `createFilter()` (ps.go:122-126), when a service argument doesn't match by full ID or full name, the code attempts an ID-prefix match (line 123-131). If the prefix matches more than one service ID, the error is returned at line 126. This is the ambiguous-prefix scenario: the provided ID prefix is too short to uniquely identify a single service.","triggerScenarios":"Running `docker service ps ab` when two services have IDs starting with `ab` (e.g., `abc123...` and `abd456...`). The prefix `ab` matches both, triggering the ambiguity error. This check occurs before any tasks are listed — it is returned from `createFilter` directly.","commonSituations":"An operator copies a short prefix of a service ID. In a large swarm with many services, short prefixes frequently collide. Also common in scripts that truncate IDs for display.","solutions":["Provide a longer service ID prefix to disambiguate — use enough characters to be unique","Use the full service name instead of an ID prefix: `docker service ps <service-name>`","List all services to find the full ID: `docker service ls`"],"exampleFix":"# before (ambiguous prefix)\ndocker service ps ab\n# error: multiple services found with provided prefix: ab\n\n# after (use full name)\ndocker service ps my-web-service\n\n# after (use longer unique prefix)\ndocker service ps abc123def456","handlingStrategy":"validation","validationCode":"// Before calling runPS, resolve ambiguous prefixes\nfunc resolveServicePrefix(ctx context.Context, c client.APIClient, prefix string) (string, error) {\n    services, err := c.ServiceList(ctx, client.ServiceListOptions{\n        Filters: make(client.Filters).Add(\"id\", prefix),\n    })\n    if err != nil {\n        return \"\", err\n    }\n    if len(services.Items) > 1 {\n        return \"\", fmt.Errorf(\"multiple services found with prefix: %s\", prefix)\n    }\n    if len(services.Items) == 0 {\n        return \"\", fmt.Errorf(\"no such service: %s\", prefix)\n    }\n    return services.Items[0].ID, nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use full service IDs or unambiguous names instead of short prefixes","In large swarms, short ID prefixes collide frequently — use at least 12 characters","Resolve service references to full IDs before batch operations"],"tags":["docker","cli","service","ps","ambiguous-id","not-found"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}