docker/cli · error

failed to remove some resources from stack: %s

Error message

failed to remove some resources from stack: %s

What it means

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.

Source

Thrown at cli/command/stack/remove.go:85

		configs, err := getStackConfigs(ctx, apiClient, namespace)
		if err != nil {
			return err
		}

		if len(services.Items)+len(networks.Items)+len(secrets.Items)+len(configs.Items) == 0 {
			_, _ = fmt.Fprintln(dockerCli.Err(), "Nothing found in stack:", namespace)
			continue
		}

		// TODO(thaJeztah): change this "hasError" boolean to return a (multi-)error for each of these functions instead.
		hasError := removeServices(ctx, dockerCli, services.Items)
		hasError = removeSecrets(ctx, dockerCli, secrets.Items) || hasError
		hasError = removeConfigs(ctx, dockerCli, configs.Items) || hasError
		hasError = removeNetworks(ctx, dockerCli, networks.Items) || hasError

		if hasError {
			errs = append(errs, errors.New("failed to remove some resources from stack: "+namespace))
			continue
		}

		if !opts.detach {
			err = waitOnTasks(ctx, apiClient, namespace)
			if err != nil {
				errs = append(errs, fmt.Errorf("failed to wait on tasks of stack: %s: %w", namespace, err))
			}
		}
	}
	return errors.Join(errs...)
}

func sortServiceByName(services []swarm.Service) func(i, j int) bool {
	return func(i, j int) bool {
		return services[i].Spec.Name < services[j].Spec.Name
	}
}

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Read the individual error lines printed above this summary to identify which specific resource failed and why.
  2. Detach or stop containers/services still using the stack's network, then re-run `docker stack rm <name>`.
  3. Verify you are talking to a swarm manager (`docker node ls`) and have sufficient permissions.
  4. Manually remove the leftover resource (`docker network rm`, `docker secret rm`, `docker config rm`) after resolving its in-use condition.
  5. Re-run the removal; it is idempotent for already-deleted resources.

Example fix

# before
docker stack rm mystack   # fails: network in use
# after
docker ps --filter network=mystack_default   # find attached containers
docker rm -f <container>
docker stack rm mystack

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/d18ad2557852d3e0.json. Report an issue: GitHub.