Browse code

Don't initialize network for 'none' mode

Fixes #7837

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>

Alexandr Morozov authored on 2014/09/04 14:50:58
Showing 3 changed files
... ...
@@ -434,7 +434,7 @@ func (container *Container) buildHostnameAndHostsFiles(IP string) error {
434 434
 
435 435
 func (container *Container) allocateNetwork() error {
436 436
 	mode := container.hostConfig.NetworkMode
437
-	if container.Config.NetworkDisabled || mode.IsContainer() || mode.IsHost() {
437
+	if container.Config.NetworkDisabled || mode.IsContainer() || mode.IsHost() || mode.IsNone() {
438 438
 		return nil
439 439
 	}
440 440
 
... ...
@@ -1828,3 +1828,21 @@ func TestRunCidFileCheckIDLength(t *testing.T) {
1828 1828
 	deleteAllContainers()
1829 1829
 	logDone("run - cidfile contains long id")
1830 1830
 }
1831
+
1832
+func TestRunNetworkNotInitializedNoneMode(t *testing.T) {
1833
+	cmd := exec.Command(dockerBinary, "run", "-d", "--net=none", "busybox", "top")
1834
+	out, _, err := runCommandWithOutput(cmd)
1835
+	if err != nil {
1836
+		t.Fatal(err)
1837
+	}
1838
+	id := strings.TrimSpace(out)
1839
+	res, err := inspectField(id, "NetworkSettings.IPAddress")
1840
+	if err != nil {
1841
+		t.Fatal(err)
1842
+	}
1843
+	if res != "" {
1844
+		t.Fatal("For 'none' mode network must not be initialized, but container got IP: %s", res)
1845
+	}
1846
+	deleteAllContainers()
1847
+	logDone("run - network must not be initialized in 'none' mode")
1848
+}
... ...
@@ -19,6 +19,10 @@ func (n NetworkMode) IsContainer() bool {
19 19
 	return len(parts) > 1 && parts[0] == "container"
20 20
 }
21 21
 
22
+func (n NetworkMode) IsNone() bool {
23
+	return n == "none"
24
+}
25
+
22 26
 type DeviceMapping struct {
23 27
 	PathOnHost        string
24 28
 	PathInContainer   string