mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Setup host networking for lxc and native
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
2c2cc051d8
commit
a785882b29
6 changed files with 20 additions and 10 deletions
|
@ -341,6 +341,8 @@ func populateCommand(c *Container, env []string) error {
|
||||||
parts := strings.SplitN(c.hostConfig.NetworkMode, ":", 2)
|
parts := strings.SplitN(c.hostConfig.NetworkMode, ":", 2)
|
||||||
switch parts[0] {
|
switch parts[0] {
|
||||||
case "none":
|
case "none":
|
||||||
|
case "host":
|
||||||
|
en.HostNetworking = true
|
||||||
case "bridge":
|
case "bridge":
|
||||||
if !c.Config.NetworkDisabled {
|
if !c.Config.NetworkDisabled {
|
||||||
network := c.NetworkSettings
|
network := c.NetworkSettings
|
||||||
|
|
|
@ -89,9 +89,10 @@ type Driver interface {
|
||||||
|
|
||||||
// Network settings of the container
|
// Network settings of the container
|
||||||
type Network struct {
|
type Network struct {
|
||||||
Interface *NetworkInterface `json:"interface"` // if interface is nil then networking is disabled
|
Interface *NetworkInterface `json:"interface"` // if interface is nil then networking is disabled
|
||||||
Mtu int `json:"mtu"`
|
Mtu int `json:"mtu"`
|
||||||
ContainerID string `json:"container_id"` // id of the container to join network.
|
ContainerID string `json:"container_id"` // id of the container to join network.
|
||||||
|
HostNetworking bool `json:"host_networking"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NetworkInterface struct {
|
type NetworkInterface struct {
|
||||||
|
|
|
@ -3,15 +3,16 @@ package lxc
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/daemon/execdriver"
|
|
||||||
"github.com/dotcloud/docker/pkg/netlink"
|
|
||||||
"github.com/dotcloud/docker/pkg/user"
|
|
||||||
"github.com/syndtr/gocapability/capability"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/dotcloud/docker/daemon/execdriver"
|
||||||
|
"github.com/dotcloud/docker/pkg/netlink"
|
||||||
|
"github.com/dotcloud/docker/pkg/user"
|
||||||
|
"github.com/syndtr/gocapability/capability"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clear environment pollution introduced by lxc-start
|
// Clear environment pollution introduced by lxc-start
|
||||||
|
|
|
@ -14,12 +14,13 @@ const LxcTemplate = `
|
||||||
lxc.network.type = veth
|
lxc.network.type = veth
|
||||||
lxc.network.link = {{.Network.Interface.Bridge}}
|
lxc.network.link = {{.Network.Interface.Bridge}}
|
||||||
lxc.network.name = eth0
|
lxc.network.name = eth0
|
||||||
{{else}}
|
lxc.network.mtu = {{.Network.Mtu}}
|
||||||
|
{{else if not .Network.HostNetworking}}
|
||||||
# network is disabled (-n=false)
|
# network is disabled (-n=false)
|
||||||
lxc.network.type = empty
|
lxc.network.type = empty
|
||||||
lxc.network.flags = up
|
lxc.network.flags = up
|
||||||
{{end}}
|
|
||||||
lxc.network.mtu = {{.Network.Mtu}}
|
lxc.network.mtu = {{.Network.Mtu}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
# root filesystem
|
# root filesystem
|
||||||
{{$ROOTFS := .Rootfs}}
|
{{$ROOTFS := .Rootfs}}
|
||||||
|
|
|
@ -53,6 +53,10 @@ func (d *driver) createContainer(c *execdriver.Command) (*libcontainer.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) createNetwork(container *libcontainer.Container, c *execdriver.Command) error {
|
func (d *driver) createNetwork(container *libcontainer.Container, c *execdriver.Command) error {
|
||||||
|
if c.Network.HostNetworking {
|
||||||
|
container.Namespaces.Get("NEWNET").Enabled = false
|
||||||
|
return nil
|
||||||
|
}
|
||||||
container.Networks = []*libcontainer.Network{
|
container.Networks = []*libcontainer.Network{
|
||||||
{
|
{
|
||||||
Mtu: c.Network.Mtu,
|
Mtu: c.Network.Mtu,
|
||||||
|
@ -90,7 +94,6 @@ func (d *driver) createNetwork(container *libcontainer.Container, c *execdriver.
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -292,6 +292,8 @@ func parseNetMode(netMode string) (string, error) {
|
||||||
return "", fmt.Errorf("'container:' netmode requires a container id or name", netMode)
|
return "", fmt.Errorf("'container:' netmode requires a container id or name", netMode)
|
||||||
}
|
}
|
||||||
return netMode, nil
|
return netMode, nil
|
||||||
|
case "host":
|
||||||
|
return netMode, nil
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("invalid netmode: %q", netMode)
|
return "", fmt.Errorf("invalid netmode: %q", netMode)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue