mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
Merge pull request #8101 from mheon/net_none_hostname
Add hostname to /etc/hosts for --net=none
This commit is contained in:
@ -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())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user