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() {