{"id":"b57b8864d56ece59","repo":"docker/cli","slug":"cannot-get-label-s-for-service-s","errorCode":null,"errorMessage":"cannot get label %s for service %s","messagePattern":"cannot get label (.+?) for service (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/stack/list_utils.go","lineNumber":26,"sourceCode":"\t\"github.com/moby/moby/client\"\n)\n\n// getStacks lists the swarm stacks with the number of services they contain.\nfunc getStacks(ctx context.Context, apiClient client.ServiceAPIClient) ([]stackSummary, error) {\n\tres, err := apiClient.ServiceList(ctx, client.ServiceListOptions{\n\t\tFilters: getAllStacksFilter(),\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tidx := make(map[string]int, len(res.Items))\n\tout := make([]stackSummary, 0, len(res.Items))\n\n\tfor _, svc := range res.Items {\n\t\tname, ok := svc.Spec.Labels[convert.LabelNamespace]\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"cannot get label \" + convert.LabelNamespace + \" for service \" + svc.ID)\n\t\t}\n\t\tif i, ok := idx[name]; ok {\n\t\t\tout[i].Services++\n\t\t\tcontinue\n\t\t}\n\t\tidx[name] = len(out)\n\t\tout = append(out, stackSummary{Name: name, Services: 1})\n\t}\n\treturn out, nil\n}\n","sourceCodeStart":8,"sourceCodeEnd":37,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/stack/list_utils.go#L8-L37","documentation":"Emitted by `docker stack ls`. getStacks (list_utils.go:12-35) lists services filtered by the stack namespace label (com.docker.stack.namespace) and groups them by that label's value; if a returned service somehow lacks the label, the CLI cannot attribute it to a stack and fails with 'cannot get label com.docker.stack.namespace for service <id>'. In practice this indicates inconsistent label state, since the filter itself selects on that label.","triggerScenarios":"`docker stack ls` where ServiceList (filtered on label com.docker.stack.namespace) returns a service whose Spec.Labels map is missing that key — e.g. a service whose labels were stripped by a later `docker service update --label-rm`, or an API/engine inconsistency.","commonSituations":"Someone removed the stack namespace label from a stack service via `docker service update --label-rm com.docker.stack.namespace`; third-party tools creating services with the label set only partially; rare engine/version mismatches where label filtering and returned specs disagree.","solutions":["Identify the offending service from the error's service ID: `docker service inspect <id> --format '{{json .Spec.Labels}}'`","Restore the label: `docker service update --label-add com.docker.stack.namespace=<stackname> <id>`, or remove the orphaned service if it shouldn't belong to a stack","Redeploy the stack with `docker stack deploy` so labels are re-applied consistently"],"exampleFix":"# before (label was stripped)\ndocker service update --label-rm com.docker.stack.namespace web\ndocker stack ls   # cannot get label com.docker.stack.namespace for service ...\n\n# after\ndocker service update --label-add com.docker.stack.namespace=mystack web\ndocker stack ls","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["swarm","stack","labels","cli"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}