1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #6391 from vieux/fix_hostname_file_net_host

fix hostname generation with --net=host
This commit is contained in:
Tibor Vass 2014-06-12 14:11:26 -07:00
commit 8091157038
2 changed files with 35 additions and 1 deletions

View file

@ -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
}

View file

@ -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")
}