mirror of
https://github.com/containers/podman.git
synced 2025-06-26 21:07:02 +08:00
Merge pull request #11605 from Luap99/hosts
Only add 127.0.0.1 entry to /etc/hosts with --net=none
This commit is contained in:
@ -2033,15 +2033,16 @@ func (c *Container) getHosts() string {
|
||||
|
||||
// Do we have a network namespace?
|
||||
netNone := false
|
||||
for _, ns := range c.config.Spec.Linux.Namespaces {
|
||||
if ns.Type == spec.NetworkNamespace {
|
||||
if ns.Path == "" && !c.config.CreateNetNS {
|
||||
netNone = true
|
||||
if c.config.NetNsCtr == "" && !c.config.CreateNetNS {
|
||||
for _, ns := range c.config.Spec.Linux.Namespaces {
|
||||
if ns.Type == spec.NetworkNamespace {
|
||||
if ns.Path == "" {
|
||||
netNone = true
|
||||
}
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If we are net=none (have a network namespace, but not connected to
|
||||
// anything) add the container's name and hostname to localhost.
|
||||
if netNone {
|
||||
|
@ -709,6 +709,18 @@ var _ = Describe("Podman run networking", func() {
|
||||
Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue())
|
||||
})
|
||||
|
||||
It("podman run with pod does not add extra 127 entry to /etc/hosts", func() {
|
||||
pod := "testpod"
|
||||
hostname := "test-hostname"
|
||||
run := podmanTest.Podman([]string{"pod", "create", "--hostname", hostname, "--name", pod})
|
||||
run.WaitWithDefaultTimeout()
|
||||
Expect(run).Should(Exit(0))
|
||||
run = podmanTest.Podman([]string{"run", "--pod", pod, ALPINE, "cat", "/etc/hosts"})
|
||||
run.WaitWithDefaultTimeout()
|
||||
Expect(run).Should(Exit(0))
|
||||
Expect(run.OutputToString()).ToNot(ContainSubstring("127.0.0.1 %s", hostname))
|
||||
})
|
||||
|
||||
ping_test := func(netns string) {
|
||||
hostname := "testctr"
|
||||
run := podmanTest.Podman([]string{"run", netns, "--hostname", hostname, ALPINE, "ping", "-c", "1", hostname})
|
||||
|
Reference in New Issue
Block a user