aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-10-20 15:18:53 -0400
committerGitHub <noreply@github.com>2020-10-20 15:18:53 -0400
commit6961b9475dbcbc6112d9c6022ac264c923ce083d (patch)
tree5536944fef8861aef90873b9687730262a2dcebc /libpod
parent36682115b0f3f5f7cfcc6bc4580e5a7435b9a4d8 (diff)
parent1b288a35ba931c0b524af550749a7c1fd48b452f (diff)
downloadpodman-6961b9475dbcbc6112d9c6022ac264c923ce083d.tar.gz
podman-6961b9475dbcbc6112d9c6022ac264c923ce083d.tar.bz2
podman-6961b9475dbcbc6112d9c6022ac264c923ce083d.zip
Merge pull request #8067 from mheon/net_host_hosts
Ensure that hostname is added to hosts with net=host
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal_linux.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index eff390e46..ffb2f5b73 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -1541,11 +1541,31 @@ func (c *Container) getHosts() string {
}
}
- if c.config.NetMode.IsSlirp4netns() {
- // When using slirp4netns, the interface gets a static IP
- hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", "10.0.2.100", c.Hostname(), c.Config().Name)
- }
hosts += c.cniHosts()
+
+ // If not making a network namespace, add our own hostname.
+ if c.Hostname() != "" {
+ if c.config.NetMode.IsSlirp4netns() {
+ // When using slirp4netns, the interface gets a static IP
+ hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", "10.0.2.100", c.Hostname(), c.config.Name)
+ } else {
+ hasNetNS := false
+ for _, ns := range c.config.Spec.Linux.Namespaces {
+ if ns.Type == spec.NetworkNamespace {
+ hasNetNS = true
+ break
+ }
+ }
+ if !hasNetNS {
+ // 127.0.1.1 and host's hostname to match Docker
+ osHostname, err := os.Hostname()
+ if err != nil {
+ osHostname = c.Hostname()
+ }
+ hosts += fmt.Sprintf("127.0.1.1 %s\n", osHostname)
+ }
+ }
+ }
return hosts
}