diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2020-06-19 06:41:58 -0400 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2020-06-20 06:20:46 -0400 |
commit | 5b3503c0a1bf93dc327145e8952ed5b05932dee5 (patch) | |
tree | 1b8c4f54f14d6eb8079d7bf4a5b5fa2f81767ce1 /libpod/container_internal_linux.go | |
parent | f403aa3baa23a64e7d6bf3fcbc815644d95b768d (diff) | |
download | podman-5b3503c0a1bf93dc327145e8952ed5b05932dee5.tar.gz podman-5b3503c0a1bf93dc327145e8952ed5b05932dee5.tar.bz2 podman-5b3503c0a1bf93dc327145e8952ed5b05932dee5.zip |
Add container name to the /etc/hosts within the container
This will allow containers that connect to the network namespace be
able to use the container name directly.
For example you can do something like
podman run -ti --name foobar fedora ping foobar
While we can do this with hostname now, this seems more natural.
Also if another container connects on the network to this container it
can do
podman run --network container:foobar fedora ping foobar
And connect to the original container,without having to discover the name.
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 | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 12c1abf1c..5ee6726e0 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -1410,13 +1410,14 @@ func (c *Container) getHosts() string { hosts += fmt.Sprintf("%s %s\n", fields[1], fields[0]) } } + if c.config.NetMode.IsSlirp4netns() { // When using slirp4netns, the interface gets a static IP - hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s\n", "10.0.2.100", c.Hostname()) + hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", "10.0.2.100", c.Hostname(), c.Config().Name) } if len(c.state.NetworkStatus) > 0 && len(c.state.NetworkStatus[0].IPs) > 0 { ipAddress := strings.Split(c.state.NetworkStatus[0].IPs[0].Address.String(), "/")[0] - hosts += fmt.Sprintf("%s\t%s\n", ipAddress, c.Hostname()) + hosts += fmt.Sprintf("%s\t%s %s\n", ipAddress, c.Hostname(), c.Config().Name) } return hosts } |