summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-12-22 16:40:10 +0100
committerGitHub <noreply@github.com>2021-12-22 16:40:10 +0100
commit2aea0a5e9beb251dc1e8a0ab67fa1460c54194b9 (patch)
treea829e4a2519c0762325dce8809fa5001a098156e /libpod
parent3280204f727bb733b1c615cff68e8377a61eb185 (diff)
parent64ce6949f23b308a432e83ec46c99ba67777ee1e (diff)
downloadpodman-2aea0a5e9beb251dc1e8a0ab67fa1460c54194b9.tar.gz
podman-2aea0a5e9beb251dc1e8a0ab67fa1460c54194b9.tar.bz2
podman-2aea0a5e9beb251dc1e8a0ab67fa1460c54194b9.zip
Merge pull request #12375 from rhatdan/hosts
Use hosts public ip address in rootless containers
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal_linux.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 9e83d6db5..edebe2393 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -2163,11 +2163,24 @@ func (c *Container) getHosts() string {
}
}
} else if c.config.NetMode.IsSlirp4netns() {
- gatewayIP, err := GetSlirp4netnsGateway(c.slirp4netnsSubnet)
- if err != nil {
- logrus.Warn("Failed to determine gatewayIP: ", err.Error())
- } else {
- hosts += fmt.Sprintf("%s host.containers.internal\n", gatewayIP.String())
+ // getLocalIP returns the non loopback local IP of the host
+ getLocalIP := func() string {
+ addrs, err := net.InterfaceAddrs()
+ if err != nil {
+ return ""
+ }
+ for _, address := range addrs {
+ // check the address type and if it is not a loopback the display it
+ if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
+ if ipnet.IP.To4() != nil {
+ return ipnet.IP.String()
+ }
+ }
+ }
+ return ""
+ }
+ if ip := getLocalIP(); ip != "" {
+ hosts += fmt.Sprintf("%s\t%s\n", ip, "host.containers.internal")
}
} else {
logrus.Debug("Network configuration does not support host.containers.internal address")