fix: respect custom networks when computing the container ip

We also change the inspect format to support network names with non alphanumeric characters. See https://github.com/moby/moby/issues/35886 for details.
This commit is contained in:
Jose Diaz-Gonzalez committed 2021-07-09 21:13:57 -04:00
1 parent a086302fc5
commit 267cc3fd54
1 file changed
+6 -1
+6 -1
View File
@@ -112,7 +112,12 @@ func GetContainerIpaddress(appName, processType, containerID string) (ipAddr str
} }
} }
b, err := common.DockerInspect(containerID, "{{.NetworkSettings.Networks.bridge.IPAddress}}") initialNetwork := reportComputedInitialNetwork(appName)
if initialNetwork == "" {
initialNetwork = "bridge"
}
b, err := common.DockerInspect(containerID, fmt.Sprintf("{{ $network := index .NetworkSettings.Networks \"%s\" }}{{ $network.IPAddress}}", initialNetwork))
if err != nil || len(b) == 0 { if err != nil || len(b) == 0 {
// docker < 1.9 compatibility // docker < 1.9 compatibility
b, err = common.DockerInspect(containerID, "{{ .NetworkSettings.IPAddress }}") b, err = common.DockerInspect(containerID, "{{ .NetworkSettings.IPAddress }}")