mirror of https://github.com/containers/podman.git
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>
This commit is contained in:
parent
a1b942ff40
commit
0864d82cb5
|
@ -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)
|
hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", "10.0.2.100", c.Hostname(), c.config.Name)
|
||||||
} else {
|
} else {
|
||||||
hasNetNS := false
|
hasNetNS := false
|
||||||
|
netNone := false
|
||||||
for _, ns := range c.config.Spec.Linux.Namespaces {
|
for _, ns := range c.config.Spec.Linux.Namespaces {
|
||||||
if ns.Type == spec.NetworkNamespace {
|
if ns.Type == spec.NetworkNamespace {
|
||||||
hasNetNS = true
|
hasNetNS = true
|
||||||
|
if ns.Path == "" && !c.config.CreateNetNS {
|
||||||
|
netNone = true
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1564,6 +1568,9 @@ func (c *Container) getHosts() string {
|
||||||
}
|
}
|
||||||
hosts += fmt.Sprintf("127.0.1.1 %s\n", osHostname)
|
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
|
return hosts
|
||||||
|
|
|
@ -584,6 +584,14 @@ var _ = Describe("Podman run networking", func() {
|
||||||
run := podmanTest.Podman([]string{"run", "--net=host", "--hostname", hostname, ALPINE, "hostname"})
|
run := podmanTest.Podman([]string{"run", "--net=host", "--hostname", hostname, ALPINE, "hostname"})
|
||||||
run.WaitWithDefaultTimeout()
|
run.WaitWithDefaultTimeout()
|
||||||
Expect(run.ExitCode()).To(BeZero())
|
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())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue