From 9494643bf1fcd38974266555e59e1b2d2573c418 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 12 Jun 2014 19:11:51 +0000 Subject: [PATCH 1/2] add test Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- integration-cli/docker_cli_run_test.go | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 545ad371ee..d8e04de8c2 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -885,3 +885,34 @@ func TestRunUnprivilegedWithChroot(t *testing.T) { logDone("run - unprivileged with chroot") } + +func TestModeHostname(t *testing.T) { + cmd := exec.Command(dockerBinary, "run", "-h=testhostname", "busybox", "cat", "/etc/hostname") + + out, _, err := runCommandWithOutput(cmd) + if err != nil { + t.Fatal(err, out) + } + + if actual := strings.Trim(out, "\r\n"); actual != "testhostname" { + t.Fatalf("expected 'testhostname', but says: '%s'", actual) + } + + cmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hostname") + + out, _, err = runCommandWithOutput(cmd) + if err != nil { + t.Fatal(err, out) + } + hostname, err := os.Hostname() + if err != nil { + t.Fatal(err) + } + if actual := strings.Trim(out, "\r\n"); actual != hostname { + t.Fatalf("expected '%s', but says: '%s'", hostname, actual) + } + + deleteAllContainers() + + logDone("run - hostname and several network modes") +} From f5979b9d0dd993a00e064114218ccdbfdaab9fe0 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 12 Jun 2014 19:20:57 +0000 Subject: [PATCH 2/2] add hostname generation with --net=host Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- daemon/container.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/daemon/container.go b/daemon/container.go index f7d2ef1f5f..239091f10b 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -886,8 +886,11 @@ func (container *Container) initializeNetworking() error { content, err := ioutil.ReadFile("/etc/hosts") if os.IsNotExist(err) { return container.buildHostnameAndHostsFiles("") + } else if err != nil { + return err } - if err != nil { + + if err := container.buildHostnameFile(); err != nil { return err }