diff options
author | Matthew Heon <matthew.heon@pm.me> | 2020-10-21 13:45:41 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2020-10-21 13:45:41 -0400 |
commit | 0864d82cb57097e6632fd2206d4e5b42861ec6e2 (patch) | |
tree | af8c00e08f04ce5714b55b4fbd3269914bf01d92 | |
parent | a1b942ff401a9315dae05d9a3210780823d12839 (diff) | |
download | podman-0864d82cb57097e6632fd2206d4e5b42861ec6e2.tar.gz podman-0864d82cb57097e6632fd2206d4e5b42861ec6e2.tar.bz2 podman-0864d82cb57097e6632fd2206d4e5b42861ec6e2.zip |
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 <matthew.heon@pm.me>
-rw-r--r-- | libpod/container_internal_linux.go | 7 | ||||
-rw-r--r-- | test/e2e/run_networking_test.go | 10 |
2 files changed, 16 insertions, 1 deletions
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 diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index 540ac5409..76d5c4cdc 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -584,6 +584,14 @@ var _ = Describe("Podman run networking", func() { run := podmanTest.Podman([]string{"run", "--net=host", "--hostname", hostname, ALPINE, "hostname"}) run.WaitWithDefaultTimeout() Expect(run.ExitCode()).To(BeZero()) - Expect(strings.Contains(run.OutputToString(), "testctr")).To(BeTrue()) + Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue()) + }) + + It("podman run with --net=none adds hostname to /etc/hosts", func() { + hostname := "testctr" + run := podmanTest.Podman([]string{"run", "--net=none", "--hostname", hostname, ALPINE, "hostname"}) + run.WaitWithDefaultTimeout() + Expect(run.ExitCode()).To(BeZero()) + Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue()) }) }) |