Skip to content

Commit

Permalink
WIP - show containers on network
Browse files Browse the repository at this point in the history
  • Loading branch information
ernesto27 committed Jun 30, 2023
1 parent ed4b60d commit 3582e7e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 21 additions & 8 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ type Docker struct {
}

type MyNetwork struct {
Name string
IPAddress string
Gateway string
Subnet string
Resource types.NetworkResource
Name string
IPAddress string
Gateway string
Subnet string
Resource types.NetworkResource
Containers []types.ContainerJSON
}

type MyContainer struct {
Expand Down Expand Up @@ -334,10 +335,22 @@ func (d *Docker) NetworkList() ([]MyNetwork, error) {
gateway = n.IPAM.Config[0].Gateway
}

network, err := d.cli.NetworkInspect(context.Background(), n.ID, types.NetworkInspectOptions{})
if err != nil {
fmt.Println(err)
}

var containers []types.ContainerJSON
for containerID := range network.Containers {
container, _ := d.cli.ContainerInspect(context.Background(), containerID)
containers = append(containers, container)
}

myNetwork = append(myNetwork, MyNetwork{
Resource: n,
Gateway: gateway,
Subnet: subnet,
Resource: network,
Gateway: gateway,
Subnet: subnet,
Containers: containers,
})
}

Expand Down
2 changes: 2 additions & 0 deletions models/network_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,7 @@ func getContentNetwork(network docker.MyNetwork) string {
{"Gateway", network.Gateway},
})

response += "# Containers\n" + network.Containers[0].Name

return response
}

0 comments on commit 3582e7e

Please sign in to comment.