diff options
-rw-r--r-- | libpod/container_internal.go | 4 | ||||
-rw-r--r-- | test/e2e/run_dns_test.go | 21 |
2 files changed, 24 insertions, 1 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index d928c4aed..9bdf4b8fc 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1157,6 +1157,10 @@ func (c *Container) generateHosts() (string, error) { hosts += fmt.Sprintf("%s %s\n", fields[1], fields[0]) } } + 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()) + } return c.writeStringToRundir("hosts", hosts) } diff --git a/test/e2e/run_dns_test.go b/test/e2e/run_dns_test.go index c5a02c776..674a57aeb 100644 --- a/test/e2e/run_dns_test.go +++ b/test/e2e/run_dns_test.go @@ -1,9 +1,10 @@ package integration import ( + "fmt" "os" + "strings" - "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -82,5 +83,23 @@ var _ = Describe("Podman run dns", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) Expect(session.OutputToString()).To(Equal("foobar")) + + session = podmanTest.Podman([]string{"run", "-d", "--hostname=foobar", ALPINE, "cat", "/etc/hosts"}) + session.WaitWithDefaultTimeout() + cid := session.OutputToString() + session = podmanTest.Podman([]string{"start", "-ia", cid}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session.LineInOutputContains("foobar") + line := strings.Split(session.OutputToStringArray()[len(session.OutputToStringArray())-1], "\t") + ip1 := line[0] + + session = podmanTest.Podman([]string{"start", "-ia", cid}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session.LineInOutputContains("foobar") + line = strings.Split(session.OutputToStringArray()[len(session.OutputToStringArray())-1], "\t") + ip2 := line[0] + Expect(ip2).To(Not(Equal(ip1))) }) }) |