Skip to content

Commit 6beb649

Browse files
committed
fix: allow network ids
1 parent 13d7074 commit 6beb649

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

examples/podman/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55

6+
"github.com/docker/docker/api/types/network"
67
"github.com/silenium-dev/docker-wrapper/pkg/client"
78
client2 "github.com/silenium-dev/docker-wrapper/pkg/client/podman/client"
89
)
@@ -36,7 +37,13 @@ func main() {
3637
println("Remote socket:", socket)
3738
}
3839

39-
hostIP, err := cli.HostIPFromContainers(context.Background(), nil)
40+
netResp, err := cli.NetworkCreate(context.Background(), "test_network", network.CreateOptions{})
41+
if err != nil {
42+
panic(err)
43+
}
44+
defer cli.NetworkRemove(context.Background(), netResp.ID)
45+
46+
hostIP, err := cli.HostIPFromContainers(context.Background(), &netResp.ID)
4047
if err != nil {
4148
panic(err)
4249
}

pkg/client/host.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ func (c *Client) HostIPFromContainers(ctx context.Context, netId *string) (net.I
7979
ipAddrStr = inspect.NetworkSettings.Gateway
8080
} else {
8181
endpoint, ok := inspect.NetworkSettings.Networks[*netId]
82+
if !ok {
83+
for _, v := range inspect.NetworkSettings.Networks {
84+
if v.NetworkID == *netId {
85+
endpoint = v
86+
ok = true
87+
break
88+
}
89+
}
90+
}
8291
if !ok {
8392
return nil, fmt.Errorf("network %s not found in container %s", *netId, cont.ID)
8493
}

0 commit comments

Comments
 (0)