diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2020-11-15 08:41:06 -0500 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2020-11-16 16:40:50 -0500 |
commit | 4ca4234af1aa02c80bf44fe8cca6b5a4e62be2c6 (patch) | |
tree | fb1c4fc303f2b86c5d5e3f6e2f252eb0ee0c5467 /libpod/container_internal_linux.go | |
parent | e59394973a7559feb42b89ea882f2ce52d0432b8 (diff) | |
download | podman-4ca4234af1aa02c80bf44fe8cca6b5a4e62be2c6.tar.gz podman-4ca4234af1aa02c80bf44fe8cca6b5a4e62be2c6.tar.bz2 podman-4ca4234af1aa02c80bf44fe8cca6b5a4e62be2c6.zip |
Make sure /etc/hosts populated correctly with networks
The --hostname and containername should always be added to containers.
Added some tests to make sure you can always ping the hostname and container
name from within the container.
Fixes: https://github.com/containers/podman/issues/8095
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod/container_internal_linux.go')
-rw-r--r-- | libpod/container_internal_linux.go | 17 |
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) } } } |