Skip to content

Commit

Permalink
Merge pull request moby#11492 from coolljt0725/fix_hostname_missing_i…
Browse files Browse the repository at this point in the history
…n_container_netmode

Fix hostname missing when a container's net mode is contaienr mode
  • Loading branch information
crosbymichael committed Mar 20, 2015
2 parents ca6512a + 74664da commit 84d3ab3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions daemon/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ func (container *Container) initializeNetworking() error {
if err != nil {
return err
}
container.HostnamePath = nc.HostnamePath
container.HostsPath = nc.HostsPath
container.ResolvConfPath = nc.ResolvConfPath
container.Config.Hostname = nc.Config.Hostname
Expand Down
25 changes: 25 additions & 0 deletions integration-cli/docker_cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,31 @@ func TestRunLinkToContainerNetMode(t *testing.T) {
logDone("run - link to a container which net mode is container success")
}

func TestRunModeNetContainerHostname(t *testing.T) {
defer deleteAllContainers()
cmd := exec.Command(dockerBinary, "run", "-i", "-d", "--name", "parent", "busybox", "top")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatalf("failed to run container: %v, output: %q", err, out)
}
cmd = exec.Command(dockerBinary, "exec", "parent", "cat", "/etc/hostname")
out, _, err = runCommandWithOutput(cmd)
if err != nil {
t.Fatalf("failed to exec command: %v, output: %q", err, out)
}

cmd = exec.Command(dockerBinary, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname")
out1, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatalf("failed to run container: %v, output: %q", err, out1)
}
if out1 != out {
t.Fatal("containers with shared net namespace should have same hostname")
}

logDone("run - containers with shared net namespace have same hostname")
}

// Regression test for #4741
func TestRunWithVolumesAsFiles(t *testing.T) {
defer deleteAllContainers()
Expand Down

0 comments on commit 84d3ab3

Please sign in to comment.