From 0864d82cb57097e6632fd2206d4e5b42861ec6e2 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Wed, 21 Oct 2020 13:45:41 -0400 Subject: Add hostname to /etc/hosts for --net=none This does not match Docker, which does not add hostname in this case, but it seems harmless enough. Fixes #8095 Signed-off-by: Matthew Heon --- libpod/container_internal_linux.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libpod') diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index ffb2f5b73..2efe0d086 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -1550,9 +1550,13 @@ func (c *Container) getHosts() string { hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", "10.0.2.100", c.Hostname(), c.config.Name) } else { hasNetNS := false + netNone := false for _, ns := range c.config.Spec.Linux.Namespaces { if ns.Type == spec.NetworkNamespace { hasNetNS = true + if ns.Path == "" && !c.config.CreateNetNS { + netNone = true + } break } } @@ -1564,6 +1568,9 @@ func (c *Container) getHosts() string { } hosts += fmt.Sprintf("127.0.1.1 %s\n", osHostname) } + if netNone { + hosts += fmt.Sprintf("127.0.1.1 %s\n", c.Hostname()) + } } } return hosts -- cgit v1.2.3-54-g00ecf