Allow extra lines in /etc/hosts

This adds a --add-host host:ip flag which appends lines to /etc/hosts.  This is needed in places where you want the container to get a different name resolution than it would through DNS.  This was submitted before as #5525, closed, and now I am re-opening.  It has come up 2 or 3 times in the last couple days.

Signed-off-by: Tim Hockin <thockin@google.com>
This commit is contained in:
Tim Hockin
2014-09-16 23:38:23 +00:00
parent 9c3eedae89
commit 68e48b65a6
8 changed files with 63 additions and 0 deletions
+17
View File
@@ -1331,6 +1331,23 @@ func TestDnsOptionsBasedOnHostResolvConf(t *testing.T) {
logDone("run - dns options based on host resolv.conf")
}
func TestRunAddHost(t *testing.T) {
defer deleteAllContainers()
cmd := exec.Command(dockerBinary, "run", "--add-host=extra:86.75.30.9", "busybox", "grep", "extra", "/etc/hosts")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
actual := strings.Trim(out, "\r\n")
if actual != "86.75.30.9\textra" {
t.Fatalf("expected '86.75.30.9\textra', but says: '%s'", actual)
}
logDone("run - add-host option")
}
// Regression test for #6983
func TestAttachStdErrOnlyTTYMode(t *testing.T) {
cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stderr", "busybox", "true")