{"record":{"id":"abd0b9bdfad97953","repo":"docker/cli","slug":"failed-to-remove-some-resources-from-stack-names","errorCode":null,"errorMessage":"failed to remove some resources from stack: {namespace}","messagePattern":"failed to remove some resources from stack: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/stack/remove.go","lineNumber":85,"sourceCode":"\n\t\tconfigs, err := getStackConfigs(ctx, apiClient, namespace)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif len(services.Items)+len(networks.Items)+len(secrets.Items)+len(configs.Items) == 0 {\n\t\t\t_, _ = fmt.Fprintln(dockerCli.Err(), \"Nothing found in stack:\", namespace)\n\t\t\tcontinue\n\t\t}\n\n\t\t// TODO(thaJeztah): change this \"hasError\" boolean to return a (multi-)error for each of these functions instead.\n\t\thasError := removeServices(ctx, dockerCli, services.Items)\n\t\thasError = removeSecrets(ctx, dockerCli, secrets.Items) || hasError\n\t\thasError = removeConfigs(ctx, dockerCli, configs.Items) || hasError\n\t\thasError = removeNetworks(ctx, dockerCli, networks.Items) || hasError\n\n\t\tif hasError {\n\t\t\terrs = append(errs, errors.New(\"failed to remove some resources from stack: \"+namespace))\n\t\t\tcontinue\n\t\t}\n\n\t\tif !opts.detach {\n\t\t\terr = waitOnTasks(ctx, apiClient, namespace)\n\t\t\tif err != nil {\n\t\t\t\terrs = append(errs, fmt.Errorf(\"failed to wait on tasks of stack: %s: %w\", namespace, err))\n\t\t\t}\n\t\t}\n\t}\n\treturn errors.Join(errs...)\n}\n\nfunc sortServiceByName(services []swarm.Service) func(i, j int) bool {\n\treturn func(i, j int) bool {\n\t\treturn services[i].Spec.Name < services[j].Spec.Name\n\t}\n}","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/stack/remove.go#L67-L103","documentation":"Returned by runRemove (cli/command/stack/remove.go:85) as a per-stack aggregate when any of removeServices/removeSecrets/removeConfigs/removeNetworks reports a failure (their hasError bool is true). It signals partial removal — some resources were deleted, some were not — typically due to networks still in use or transient API errors.","triggerScenarios":"`docker stack rm <stack>` where at least one resource deletion fails: a network still has attached endpoints, a service/config was removed concurrently, or an API/RBAC error occurred mid-loop.","commonSituations":"A network still referenced by a lingering container or task; a race with concurrent cleanup; permission limits on the API; resources already gone between list and delete.","solutions":["Re-run `docker stack rm <stack>`; transient or dependency-ordered failures often clear once services drain.","List and remove stubborn resources manually: `docker network rm <id>`, `docker service rm <id>`.","Ensure no containers are still attached to stack networks before removal (stop tasks first).","Check stderr above the error line — each remove* helper prints the specific per-resource failure."],"exampleFix":"// before\ndocker stack rm mystack   # exits with: failed to remove some resources from stack: mystack\n\n// after: read the per-resource stderr, then target leftovers\ndocker network rm mystack_default   # e.g. network still in use\ndocker stack rm mystack            # retry","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Retry stack removal with backoff; collect per-resource failures.\nfor attempt := 0; attempt < 3; attempt++ {\n\terr := runRemove(ctx, dockerCli, opts)\n\tif err == nil { break }\n\tif !isRetryableRemoveErr(err) { return err }\n\ttime.Sleep(time.Duration(attempt+1) * time.Second)\n}","preventionTips":["Drain/stop services before removing the stack so networks free up.","Parse stderr for the specific per-resource failure printed above the aggregate error.","Idempotently remove leftover networks/configs/secrets after the main rm."],"tags":["docker","swarm","stack","remove","cleanup","partial-failure"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}