Don't initialize network for 'none' mode

Fixes #7837

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>
This commit is contained in:
Alexandr Morozov 2014-09-04 09:50:58 +04:00
parent 58dc474e65
commit ba24820284
3 changed files with 23 additions and 1 deletions

View file

@ -434,7 +434,7 @@ func (container *Container) buildHostnameAndHostsFiles(IP string) error {
func (container *Container) allocateNetwork() error {
mode := container.hostConfig.NetworkMode
if container.Config.NetworkDisabled || mode.IsContainer() || mode.IsHost() {
if container.Config.NetworkDisabled || mode.IsContainer() || mode.IsHost() || mode.IsNone() {
return nil
}

View file

@ -1828,3 +1828,21 @@ func TestRunCidFileCheckIDLength(t *testing.T) {
deleteAllContainers()
logDone("run - cidfile contains long id")
}
func TestRunNetworkNotInitializedNoneMode(t *testing.T) {
cmd := exec.Command(dockerBinary, "run", "-d", "--net=none", "busybox", "top")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err)
}
id := strings.TrimSpace(out)
res, err := inspectField(id, "NetworkSettings.IPAddress")
if err != nil {
t.Fatal(err)
}
if res != "" {
t.Fatal("For 'none' mode network must not be initialized, but container got IP: %s", res)
}
deleteAllContainers()
logDone("run - network must not be initialized in 'none' mode")
}

View file

@ -19,6 +19,10 @@ func (n NetworkMode) IsContainer() bool {
return len(parts) > 1 && parts[0] == "container"
}
func (n NetworkMode) IsNone() bool {
return n == "none"
}
type DeviceMapping struct {
PathOnHost string
PathInContainer string