44 "fmt"
55 "strings"
66
7- "github.com/docker/docker/api/types"
7+ "github.com/docker/docker/api/types/container "
88 "github.com/docker/docker/api/types/filters"
99 "github.com/docker/docker/api/types/network"
1010 "github.com/docker/docker/client"
@@ -38,9 +38,6 @@ type Network struct {
3838func (n Network ) GetID () string { return n .ID }
3939func (n Network ) GetCells () []string {
4040 containersStr := fmt .Sprintf ("%d" , n .Containers )
41- if n .Containers <= 0 {
42- containersStr = ""
43- }
4441 return []string {n .ID [:12 ], n .Name , n .Driver , n .Scope , containersStr , n .Created , n .Internal , n .Subnet }
4542}
4643
@@ -84,6 +81,24 @@ func (m *Manager) List() ([]common.Resource, error) {
8481 return nil , err
8582 }
8683
84+ // Count containers per network
85+ counts := make (map [string ]int )
86+ containers , err := m .cli .ContainerList (m .ctx , container.ListOptions {All : true })
87+ // Debug: force error check visibility
88+ if err != nil {
89+ // In a real app we might log this or handle it, but here we just ignore
90+ } else {
91+ for _ , c := range containers {
92+ if c .NetworkSettings != nil {
93+ for _ , net := range c .NetworkSettings .Networks {
94+ if net .NetworkID != "" {
95+ counts [net .NetworkID ]++
96+ }
97+ }
98+ }
99+ }
100+ }
101+
87102 var res []common.Resource
88103 for _ , n := range list {
89104 internal := "No"
@@ -101,6 +116,11 @@ func (m *Manager) List() ([]common.Resource, error) {
101116 }
102117 }
103118
119+ count := counts [n .ID ]
120+ if len (n .Containers ) > count {
121+ count = len (n .Containers )
122+ }
123+
104124 res = append (res , Network {
105125 ID : n .ID ,
106126 Name : n .Name ,
@@ -109,7 +129,7 @@ func (m *Manager) List() ([]common.Resource, error) {
109129 Created : common .FormatTime (n .Created .Unix ()),
110130 Internal : internal ,
111131 Subnet : strings .Join (subnets , "," ),
112- Containers : len ( n . Containers ) ,
132+ Containers : count ,
113133 })
114134 }
115135 return res , nil
0 commit comments