From f50fab5b0c7cafd71cbf3bd7737c819c371cd1e2 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Fri, 11 Feb 2022 14:12:17 -0500 Subject: [PATCH] Return slirp ip information from getHosts() When one container shares the network namespace with another container or with a Pod, there should be an entry added to the /etc/hosts file for the second container. Fixes: https://github.com/containers/podman/issues/12003 Signed-off-by: Daniel J Walsh --- libpod/container_internal_linux.go | 10 ++++++++++ libpod/networking_linux.go | 1 + test/e2e/run_networking_test.go | 1 + 3 files changed, 12 insertions(+) diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index afa351c173..dcb9075e89 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -2377,7 +2377,17 @@ func (c *Container) getHosts() string { if depCtr != nil { host := "" + if depCtr.config.NetMode.IsSlirp4netns() { + // When using slirp4netns, the interface gets a static IP + if slirp4netnsIP, err := GetSlirp4netnsIP(depCtr.slirp4netnsSubnet); err != nil { + logrus.Warnf("Failed to determine slirp4netnsIP: %v", err.Error()) + } else { + return fmt.Sprintf("%s\t%s %s\n", slirp4netnsIP.String(), c.Hostname(), c.config.Name) + } + } outer: + // Paul this is returning nothing, even though I know depctr is up and + // running with an IP Address in rootfull mode? for net, status := range depCtr.getNetworkStatus() { network, err := c.runtime.network.NetworkInspect(net) // only add the host entry for bridge networks diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index 19d5c7f761..2603a98be9 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package libpod diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index aa1887f84d..e6fa5fed6e 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -633,6 +633,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) exec4.WaitWithDefaultTimeout() Expect(exec4).Should(Exit(0)) Expect(exec4.OutputToString()).To(ContainSubstring("192.0.2.2 test1")) + Expect(exec4.OutputToString()).To(ContainSubstring(ctrName2)) }) It("podman run /etc/hosts contains --hostname", func() {