From 934266b02bc5312ad6626872de21c49979b288b8 Mon Sep 17 00:00:00 2001 From: Alessio Attilio Date: Tue, 20 Jan 2026 19:54:26 +0100 Subject: [PATCH] use 127.0.0.1 for host.containers.internal with host network --- libnetwork/etchosts/ip.go | 6 ++++++ 1 file changed, 6 insertions(+) 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