зеркало из https://github.com/microsoft/docker.git
Merge pull request #7878 from LK4D4/fix_net_for_none
Don't initialize network for 'none' mode
This commit is contained in:
Коммит
1a2a4f61ab
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче