feat: add support for host-mode networking

In host-mode, there is no 'bridge' network by default, so we return an invalid IP address of 'no value'. Instead, return '127.0.0.1' for those containers.
This commit is contained in:
Jose Diaz-Gonzalez
2020-01-15 14:15:50 -05:00
parent 7dd4efad39
commit 8958ea0f2d
2 changed files with 23 additions and 0 deletions

View File

@@ -95,6 +95,12 @@ func GetContainerIpaddress(appName, processType, containerID string) (ipAddr str
return
}
if b, err := common.DockerInspect(containerID, "'{{ .HostConfig.NetworkMode }}'"); err == nil {
if string(b[:]) == "host" {
return "127.0.0.1"
}
}
b, err := common.DockerInspect(containerID, "'{{.NetworkSettings.Networks.bridge.IPAddress}}'")
if err != nil || len(b) == 0 {
// docker < 1.9 compatibility