{"id":"d18ad2557852d3e0","repo":"docker/cli","slug":"failed-to-remove-some-resources-from-stack-s","errorCode":null,"errorMessage":"failed to remove some resources from stack: %s","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/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/stack/remove.go#L67-L103","documentation":"Emitted by `docker stack rm` when at least one resource belonging to the stack (services, secrets, configs, or networks) could not be deleted. The command attempts removal of each resource category individually via removeServices/removeSecrets/removeConfigs/removeNetworks, tracks a hasError boolean, and appends this aggregate error per failing stack namespace so the command exits non-zero while still processing remaining stacks.","triggerScenarios":"Running `docker stack rm <name>` where any ServiceRemove, SecretRemove, ConfigRemove, or NetworkRemove API call returns an error — e.g. a network still has attached containers, a secret/config is in use by a non-stack service, the daemon connection drops mid-removal, or the caller lacks manager privileges partway through.","commonSituations":"Overlay networks failing to delete because standalone containers or services outside the stack are still attached; removing a stack while tasks are still shutting down; running against a worker node instead of a manager; concurrent stack removals racing on shared resources.","solutions":["Read the individual error lines printed above this summary to identify which specific resource failed and why.","Detach or stop containers/services still using the stack's network, then re-run `docker stack rm <name>`.","Verify you are talking to a swarm manager (`docker node ls`) and have sufficient permissions.","Manually remove the leftover resource (`docker network rm`, `docker secret rm`, `docker config rm`) after resolving its in-use condition.","Re-run the removal; it is idempotent for already-deleted resources."],"exampleFix":"# before\ndocker stack rm mystack   # fails: network in use\n# after\ndocker ps --filter network=mystack_default   # find attached containers\ndocker rm -f <container>\ndocker stack rm mystack","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker","swarm","stack","resource-cleanup"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}