summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-11-17 12:45:50 +0100
committerGitHub <noreply@github.com>2020-11-17 12:45:50 +0100
commit7d067afac716927b26c452d4d75478b9f13abd62 (patch)
treefce10e3d5f3aa0d0ec9470c70af02e728cd79067 /libpod
parentd30f9ae8b6a21fbef6704e372e9ec74fc689875e (diff)
parent4ca4234af1aa02c80bf44fe8cca6b5a4e62be2c6 (diff)
downloadpodman-7d067afac716927b26c452d4d75478b9f13abd62.tar.gz
podman-7d067afac716927b26c452d4d75478b9f13abd62.tar.bz2
podman-7d067afac716927b26c452d4d75478b9f13abd62.zip
Merge pull request #8347 from rhatdan/hostname
Make sure /etc/hosts populated correctly with networks
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal_linux.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 83d5c20cb..7b21e284b 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -1354,6 +1354,14 @@ func (c *Container) makeBindMounts() error {
return err
}
}
+ } else {
+ if !c.config.UseImageHosts && c.state.BindMounts["/etc/hosts"] == "" {
+ newHosts, err := c.generateHosts("/etc/hosts")
+ if err != nil {
+ return errors.Wrapf(err, "error creating hosts file for container %s", c.ID())
+ }
+ c.state.BindMounts["/etc/hosts"] = newHosts
+ }
}
// SHM is always added when we mount the container
@@ -1614,14 +1622,11 @@ func (c *Container) getHosts() string {
}
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)
+ osHostname, _ := os.Hostname()
+ hosts += fmt.Sprintf("127.0.1.1 %s %s %s\n", osHostname, c.Hostname(), c.config.Name)
}
if netNone {
- hosts += fmt.Sprintf("127.0.1.1 %s\n", c.Hostname())
+ hosts += fmt.Sprintf("127.0.1.1 %s %s\n", c.Hostname(), c.config.Name)
}
}
}