fix(docker): host network_mode port selection

This commit is contained in:
yusing
2025-05-07 23:26:51 +08:00
parent 4daefa19d1
commit 1e80ad2a44
3 changed files with 48 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import (
"strings"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/yusing/go-proxy/agent/pkg/agent"
config "github.com/yusing/go-proxy/internal/config/types"
"github.com/yusing/go-proxy/internal/gperr"
@@ -218,13 +219,15 @@ func (c *Container) UpdatePorts() error {
}
for port := range inspect.Config.ExposedPorts {
if port.Int() == 0 {
proto, portStr := nat.SplitProtoPort(string(port))
portInt, _ := nat.ParsePort(portStr)
if portInt == 0 {
continue
}
c.PublicPortMapping[port.Int()] = container.Port{
PublicPort: uint16(port.Int()),
PrivatePort: uint16(port.Int()),
Type: port.Proto(),
c.PublicPortMapping[portInt] = container.Port{
PublicPort: uint16(portInt),
PrivatePort: uint16(portInt),
Type: proto,
}
}
return nil