diff --git a/libnetwork/etchosts/ip.go b/libnetwork/etchosts/ip.go index f11147f2d..f085e1408 100644 --- a/libnetwork/etchosts/ip.go +++ b/libnetwork/etchosts/ip.go @@ -28,6 +28,8 @@ type HostContainersInternalOptions struct { // lower priority than the containers.conf config option. // This is used for the pasta --map-guest-addr ip. PreferIP string + // HostNetwork is true if the container is using host networking. + HostNetwork bool } // Lookup "host.containers.internal" dns name so we can add it to /etc/hosts when running inside podman machine. @@ -61,6 +63,10 @@ func GetHostContainersInternalIP(opts HostContainersInternalOptions) string { return opts.Conf.Containers.HostContainersInternalIP } + if opts.HostNetwork { + return "127.0.0.1" + } + // caller has a specific ip it prefers if opts.PreferIP != "" { return opts.PreferIP