Merge pull request #7878 from LK4D4/fix_net_for_none

Don't initialize network for 'none' mode
This commit is contained in:
Tibor Vass 2014-09-04 15:30:03 -07:00
Родитель d3b5bf5d24 ba24820284
Коммит 1a2a4f61ab
3 изменённых файлов: 23 добавлений и 1 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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