Fix issue #4681 - No loopback interface within container when networking is disabled.
Docker-DCO-1.1-Signed-off-by: Timothy Hobbs <timothyhobbs@seznam.cz> (github: https://github.com/timthelion) Remove loopback code from veth strategy Docker-DCO-1.1-Signed-off-by: Timothy Hobbs <timothyhobbs@seznam.cz> (github: https://github.com/timthelion) Looback strategy: Get rid of uneeded code in Create Docker-DCO-1.1-Signed-off-by: Timothy Hobbs <timothyhobbs@seznam.cz> (github: https://github.com/timthelion) Use append when building network strategy list Docker-DCO-1.1-Signed-off-by: Timothy Hobbs <timothyhobbs@seznam.cz> (github: https://github.com/timthelion) Swap loopback and veth strategies in Networks list Docker-DCO-1.1-Signed-off-by: Timothy Hobbs <timothyhobbs@seznam.cz> (github: https://github.com/timthelion) Revert "Swap loopback and veth strategies in Networks list" This reverts commit 3b8b2c8454171d79bed5e9a80165172617e92fc7. Docker-DCO-1.1-Signed-off-by: Timothy Hobbs <timothyhobbs@seznam.cz> (github: https://github.com/timthelion) When initializing networks, only return from the loop if there is an error Docker-DCO-1.1-Signed-off-by: Timothy Hobbs <timothyhobbs@seznam.cz> (github: https://github.com/timthelion)
This commit is contained in:
parent
dce2f20bec
commit
1cad0a1d6c
4 changed files with 31 additions and 8 deletions
24
libcontainer/network/loopback.go
Normal file
24
libcontainer/network/loopback.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Loopback is a network strategy that provides a basic loopback device
|
||||||
|
type Loopback struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Loopback) Create(n *libcontainer.Network, nspid int, context libcontainer.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Loopback) Initialize(config *libcontainer.Network, context libcontainer.Context) error {
|
||||||
|
if err := SetMtu("lo", config.Mtu); err != nil {
|
||||||
|
return fmt.Errorf("set lo mtu to %d %s", config.Mtu, err)
|
||||||
|
}
|
||||||
|
if err := InterfaceUp("lo"); err != nil {
|
||||||
|
return fmt.Errorf("lo up %s", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ var (
|
||||||
|
|
||||||
var strategies = map[string]NetworkStrategy{
|
var strategies = map[string]NetworkStrategy{
|
||||||
"veth": &Veth{},
|
"veth": &Veth{},
|
||||||
|
"loopback": &Loopback{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkStrategy represents a specific network configuration for
|
// NetworkStrategy represents a specific network configuration for
|
||||||
|
|
|
@ -68,12 +68,6 @@ func (v *Veth) Initialize(config *libcontainer.Network, context libcontainer.Con
|
||||||
if err := InterfaceUp("eth0"); err != nil {
|
if err := InterfaceUp("eth0"); err != nil {
|
||||||
return fmt.Errorf("eth0 up %s", err)
|
return fmt.Errorf("eth0 up %s", err)
|
||||||
}
|
}
|
||||||
if err := SetMtu("lo", config.Mtu); err != nil {
|
|
||||||
return fmt.Errorf("set lo mtu to %d %s", config.Mtu, err)
|
|
||||||
}
|
|
||||||
if err := InterfaceUp("lo"); err != nil {
|
|
||||||
return fmt.Errorf("lo up %s", err)
|
|
||||||
}
|
|
||||||
if config.Gateway != "" {
|
if config.Gateway != "" {
|
||||||
if err := SetDefaultGateway(config.Gateway); err != nil {
|
if err := SetDefaultGateway(config.Gateway); err != nil {
|
||||||
return fmt.Errorf("set gateway to %s %s", config.Gateway, err)
|
return fmt.Errorf("set gateway to %s %s", config.Gateway, err)
|
||||||
|
|
|
@ -134,7 +134,11 @@ func setupNetwork(container *libcontainer.Container, context libcontainer.Contex
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return strategy.Initialize(config, context)
|
|
||||||
|
err1 := strategy.Initialize(config, context)
|
||||||
|
if err1 != nil {
|
||||||
|
return err1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue