fix docker port discovery

This commit is contained in:
yusing 2024-03-29 13:20:44 +00:00
parent c789c69c86
commit fdab026a3b
2 changed files with 6 additions and 6 deletions

Binary file not shown.

View file

@ -61,10 +61,10 @@ func (p *Provider) getContainerProxyConfigs(container types.Container, clientIP
} }
} }
if config.Port == "" { if config.Port == "" {
config.Port = fmt.Sprintf("%d", selectPort(container)) config.Port = fmt.Sprintf("%d", selectPort(&container))
} }
if config.Port == "0" { if config.Port == "0" {
l.Debugf("no ports exposed, ignored") l.Infof("no ports exposed, ignored")
continue continue
} }
if config.Scheme == "" { if config.Scheme == "" {
@ -193,14 +193,14 @@ func (p *Provider) getDockerProxyConfigs() (ProxyConfigSlice, error) {
func getPublicPort(p types.Port) uint16 { return p.PublicPort } func getPublicPort(p types.Port) uint16 { return p.PublicPort }
func getPrivatePort(p types.Port) uint16 { return p.PrivatePort } func getPrivatePort(p types.Port) uint16 { return p.PrivatePort }
func selectPort(c types.Container) uint16 { func selectPort(c *types.Container) uint16 {
if c.HostConfig.NetworkMode == "host" { if c.HostConfig.NetworkMode == "host" {
return selectPortInternal(c, getPrivatePort) return selectPortInternal(c, getPublicPort)
} }
return selectPortInternal(c, getPublicPort) return selectPortInternal(c, getPrivatePort)
} }
func selectPortInternal(c types.Container, getPort func(types.Port) uint16) uint16 { func selectPortInternal(c *types.Container, getPort func(types.Port) uint16) uint16 {
for _, p := range c.Ports { for _, p := range c.Ports {
if port := getPort(p); port != 0 { if port := getPort(p); port != 0 {
return port return port