Signed-off-by: Lei Jitang <leijitang@huawei.com>
| ... | ... |
@@ -1222,6 +1222,7 @@ func (container *Container) initializeNetworking() error {
|
| 1222 | 1222 |
if err != nil {
|
| 1223 | 1223 |
return err |
| 1224 | 1224 |
} |
| 1225 |
+ container.HostnamePath = nc.HostnamePath |
|
| 1225 | 1226 |
container.HostsPath = nc.HostsPath |
| 1226 | 1227 |
container.ResolvConfPath = nc.ResolvConfPath |
| 1227 | 1228 |
container.Config.Hostname = nc.Config.Hostname |
| ... | ... |
@@ -412,6 +412,31 @@ func TestRunLinkToContainerNetMode(t *testing.T) {
|
| 412 | 412 |
logDone("run - link to a container which net mode is container success")
|
| 413 | 413 |
} |
| 414 | 414 |
|
| 415 |
+func TestRunModeNetContainerHostname(t *testing.T) {
|
|
| 416 |
+ defer deleteAllContainers() |
|
| 417 |
+ cmd := exec.Command(dockerBinary, "run", "-i", "-d", "--name", "parent", "busybox", "top") |
|
| 418 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 419 |
+ if err != nil {
|
|
| 420 |
+ t.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 421 |
+ } |
|
| 422 |
+ cmd = exec.Command(dockerBinary, "exec", "parent", "cat", "/etc/hostname") |
|
| 423 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 424 |
+ if err != nil {
|
|
| 425 |
+ t.Fatalf("failed to exec command: %v, output: %q", err, out)
|
|
| 426 |
+ } |
|
| 427 |
+ |
|
| 428 |
+ cmd = exec.Command(dockerBinary, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname") |
|
| 429 |
+ out1, _, err := runCommandWithOutput(cmd) |
|
| 430 |
+ if err != nil {
|
|
| 431 |
+ t.Fatalf("failed to run container: %v, output: %q", err, out1)
|
|
| 432 |
+ } |
|
| 433 |
+ if out1 != out {
|
|
| 434 |
+ t.Fatal("containers with shared net namespace should have same hostname")
|
|
| 435 |
+ } |
|
| 436 |
+ |
|
| 437 |
+ logDone("run - containers with shared net namespace have same hostname")
|
|
| 438 |
+} |
|
| 439 |
+ |
|
| 415 | 440 |
// Regression test for #4741 |
| 416 | 441 |
func TestRunWithVolumesAsFiles(t *testing.T) {
|
| 417 | 442 |
defer deleteAllContainers() |