{"record":{"id":"006c55a35aaf6c7b","repo":"docker/compose","slug":"failed-to-remove-network-s-w","errorCode":null,"errorMessage":"failed to remove network %s: %w","messagePattern":"failed to remove network (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compose/down.go","lineNumber":231,"sourceCode":"\t\t\ts.events.On(newEvent(eventName, api.Warning, \"No resource found to remove\"))\n\t\t\treturn nil\n\t\t}\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tnw := nwInspect.Network\n\t\tif len(nw.Containers) > 0 {\n\t\t\ts.events.On(newEvent(eventName, api.Warning, \"Resource is still in use\"))\n\t\t\tfound++\n\t\t\tcontinue\n\t\t}\n\n\t\tif _, err := s.apiClient().NetworkRemove(ctx, net.ID, client.NetworkRemoveOptions{}); err != nil {\n\t\t\tif errdefs.IsNotFound(err) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ts.events.On(errorEvent(eventName, err.Error()))\n\t\t\treturn fmt.Errorf(\"failed to remove network %s: %w\", name, err)\n\t\t}\n\t\ts.events.On(removedEvent(eventName))\n\t\tfound++\n\t}\n\n\tif found == 0 {\n\t\t// in practice, it's extremely unlikely for this to ever occur, as it'd\n\t\t// mean the network was present when we queried at the start of this\n\t\t// method but was then deleted by something else in the interim\n\t\ts.events.On(newEvent(eventName, api.Warning, \"No resource found to remove\"))\n\t\treturn nil\n\t}\n\treturn nil\n}\n\nfunc (s *composeService) removeVolume(ctx context.Context, id string) error {\n\tresource := fmt.Sprintf(\"Volume %s\", id)\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/down.go#L213-L249","documentation":"NetworkRemove returned a non-NotFound error while pruning a compose network during down. Still-in-use networks are only warned about and skipped; this error means the actual delete API call failed (permissions, daemon state, plugin driver error) and down aborts.","triggerScenarios":"removeNetwork loop calling NetworkRemove(net.ID) and getting e.g. an authorization error, 'network has active endpoints' variants surfaced as errors, or daemon internal failure during 'docker compose down'.","commonSituations":"Endpoints attached between the inspect and the remove (race); rootless/permission mismatch; overlay driver issues on Swarm nodes; daemon degraded mid-teardown.","solutions":["Detach/stop remaining endpoints: docker network inspect <net> to find containers, then docker rm -f them, and re-run down","If the wrapped error is permission-related, run with correct user/context","docker network rm <id> manually to see the daemon's full error","Re-run docker compose down — removal is retried and NotFound is tolerated"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure no endpoints remain before down\nnw, _ := cli.NetworkInspect(ctx, netName, client.NetworkInspectOptions{})\nif len(nw.Containers) > 0 {\n    for id := range nw.Containers { _ = cli.ContainerRemove(ctx, id, client.ContainerRemoveOptions{Force: true}) }\n}","typeGuard":null,"tryCatchPattern":"if err := compose.Down(...); err != nil {\n    if strings.Contains(err.Error(), \"failed to remove network\") {\n        // inspect endpoints, force-remove containers, retry down once\n    }\n    return err\n}","preventionTips":["Stop dependent containers before removing shared networks","Re-run down after manual cleanup","Run manual docker network rm to get full daemon diagnostics"],"tags":["network","teardown","docker-api"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}