From a1270d6cc7e2d24f3d461c13d3e628285889b969 Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Fri, 29 May 2020 03:58:04 +1000 Subject: [PATCH] Use specified network for "container" network mode --- pkg/provider/docker/config.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/provider/docker/config.go b/pkg/provider/docker/config.go index dc7eb4f95..1f35e7897 100644 --- a/pkg/provider/docker/config.go +++ b/pkg/provider/docker/config.go @@ -345,7 +345,23 @@ func (p Provider) getIPAddress(ctx context.Context, container dockerData) string logger.Warnf("Unable to get IP address for container %s : Failed to inspect container ID %s, error: %s", container.Name, connectedContainer, err) return "" } - return p.getIPAddress(ctx, parseContainer(containerInspected)) + + // Check connected container for traefik.docker.network, falling back to + // the network specified on the current container. + containerParsed := parseContainer(containerInspected) + extraConf, err := p.getConfiguration(containerParsed) + + if err != nil { + logger.Warnf("Unable to get IP address for container %s : failed to get extra configuration for container %s: %s", container.Name, containerInspected.Name, err) + return "" + } + + if extraConf.Docker.Network == "" { + extraConf.Docker.Network = container.ExtraConf.Docker.Network + } + + containerParsed.ExtraConf = extraConf + return p.getIPAddress(ctx, containerParsed) } for _, network := range container.NetworkSettings.Networks {