Only warn about missing docker network when network_mode is not host or container

This commit is contained in:
Senan Kelly 2023-03-24 00:26:07 +00:00 committed by GitHub
parent 77509b0913
commit ac9d88e5a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -310,6 +310,7 @@ func (p *Provider) getIPPort(ctx context.Context, container dockerData, serverPo
func (p Provider) getIPAddress(ctx context.Context, container dockerData) string { func (p Provider) getIPAddress(ctx context.Context, container dockerData) string {
logger := log.FromContext(ctx) logger := log.FromContext(ctx)
netNotFound := false
if container.ExtraConf.Docker.Network != "" { if container.ExtraConf.Docker.Network != "" {
settings := container.NetworkSettings settings := container.NetworkSettings
if settings.Networks != nil { if settings.Networks != nil {
@ -318,7 +319,8 @@ func (p Provider) getIPAddress(ctx context.Context, container dockerData) string
return network.Addr return network.Addr
} }
logger.Warnf("Could not find network named '%s' for container '%s'! Maybe you're missing the project's prefix in the label? Defaulting to first available network.", container.ExtraConf.Docker.Network, container.Name) netNotFound = true
logger.Debugf("Could not find network named %q for container %q. Maybe you're missing the project's prefix in the label?", container.ExtraConf.Docker.Network, container.Name)
} }
} }
@ -367,6 +369,9 @@ func (p Provider) getIPAddress(ctx context.Context, container dockerData) string
} }
for _, network := range container.NetworkSettings.Networks { for _, network := range container.NetworkSettings.Networks {
if netNotFound {
logger.Warnf("Defaulting to first available network (%q) for container %q.", network, container.Name)
}
return network.Addr return network.Addr
} }