mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-04 07:48:44 +00:00
@@ -32,6 +32,7 @@ type CommonConfig struct {
|
||||
Pidfile string
|
||||
Root string
|
||||
TrustKeyPath string
|
||||
DefaultNetwork string
|
||||
}
|
||||
|
||||
// InstallCommonFlags adds command-line options to the top-level flag parser for
|
||||
@@ -50,6 +51,7 @@ func (config *Config) InstallCommonFlags() {
|
||||
flag.IntVar(&config.Mtu, []string{"#mtu", "-mtu"}, 0, "Set the containers network MTU")
|
||||
flag.BoolVar(&config.EnableCors, []string{"#api-enable-cors", "#-api-enable-cors"}, false, "Enable CORS headers in the remote API, this is deprecated by --api-cors-header")
|
||||
flag.StringVar(&config.CorsHeaders, []string{"-api-cors-header"}, "", "Set CORS headers in the remote API")
|
||||
flag.StringVar(&config.DefaultNetwork, []string{"-default-network"}, "", "Set default network")
|
||||
// FIXME: why the inconsistency between "hosts" and "sockets"?
|
||||
opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "DNS server to use")
|
||||
opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "DNS search domains to use")
|
||||
|
||||
@@ -737,17 +737,47 @@ func (container *Container) buildCreateEndpointOptions() ([]libnetwork.EndpointO
|
||||
return createOptions, nil
|
||||
}
|
||||
|
||||
func createDefaultNetwork(controller libnetwork.NetworkController) (libnetwork.Network, error) {
|
||||
createOptions := []libnetwork.NetworkOption{}
|
||||
genericOption := options.Generic{}
|
||||
dnet := controller.Config().Daemon.DefaultNetwork
|
||||
driver := controller.Config().Daemon.DefaultDriver
|
||||
|
||||
// Bridge driver is special due to legacy reasons
|
||||
if runconfig.NetworkMode(driver).IsBridge() {
|
||||
genericOption[netlabel.GenericData] = map[string]interface{}{
|
||||
"BridgeName": dnet,
|
||||
"AllowNonDefaultBridge": "true",
|
||||
}
|
||||
networkOption := libnetwork.NetworkOptionGeneric(genericOption)
|
||||
createOptions = append(createOptions, networkOption)
|
||||
}
|
||||
|
||||
return controller.NewNetwork(driver, dnet, createOptions...)
|
||||
}
|
||||
|
||||
func (container *Container) AllocateNetwork() error {
|
||||
mode := container.hostConfig.NetworkMode
|
||||
controller := container.daemon.netController
|
||||
if container.Config.NetworkDisabled || mode.IsContainer() {
|
||||
return nil
|
||||
}
|
||||
|
||||
networkName := mode.NetworkName()
|
||||
if mode.IsDefault() {
|
||||
networkName = controller.Config().Daemon.DefaultNetwork
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
n, err := container.daemon.netController.NetworkByName(string(mode))
|
||||
n, err := controller.NetworkByName(networkName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error locating network with name %s: %v", string(mode), err)
|
||||
if !mode.IsDefault() {
|
||||
return fmt.Errorf("error locating network with name %s: %v", networkName, err)
|
||||
}
|
||||
if n, err = createDefaultNetwork(controller); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
createOptions, err := container.buildCreateEndpointOptions()
|
||||
@@ -790,9 +820,8 @@ func (container *Container) initializeNetworking() error {
|
||||
// Make sure NetworkMode has an acceptable value before
|
||||
// initializing networking.
|
||||
if container.hostConfig.NetworkMode == runconfig.NetworkMode("") {
|
||||
container.hostConfig.NetworkMode = runconfig.NetworkMode("bridge")
|
||||
container.hostConfig.NetworkMode = runconfig.NetworkMode("default")
|
||||
}
|
||||
|
||||
if container.hostConfig.NetworkMode.IsContainer() {
|
||||
// we need to get the hosts files from the container to join
|
||||
nc, err := container.getNetworkedContainer()
|
||||
|
||||
+35
-1
@@ -5,6 +5,7 @@ package daemon
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -24,6 +25,8 @@ import (
|
||||
"github.com/docker/docker/volume/local"
|
||||
"github.com/docker/libcontainer/label"
|
||||
"github.com/docker/libnetwork"
|
||||
nwapi "github.com/docker/libnetwork/api"
|
||||
nwconfig "github.com/docker/libnetwork/config"
|
||||
"github.com/docker/libnetwork/netlabel"
|
||||
"github.com/docker/libnetwork/options"
|
||||
)
|
||||
@@ -264,8 +267,35 @@ func isNetworkDisabled(config *Config) bool {
|
||||
return config.Bridge.Iface == disableNetworkBridge
|
||||
}
|
||||
|
||||
func networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
|
||||
options := []nwconfig.Option{}
|
||||
if dconfig == nil {
|
||||
return options, nil
|
||||
}
|
||||
if strings.TrimSpace(dconfig.DefaultNetwork) != "" {
|
||||
dn := strings.Split(dconfig.DefaultNetwork, ":")
|
||||
if len(dn) < 2 {
|
||||
return nil, fmt.Errorf("default network daemon config must be of the form NETWORKDRIVER:NETWORKNAME")
|
||||
}
|
||||
options = append(options, nwconfig.OptionDefaultDriver(dn[0]))
|
||||
options = append(options, nwconfig.OptionDefaultNetwork(strings.Join(dn[1:], ":")))
|
||||
} else {
|
||||
dd := runconfig.DefaultDaemonNetworkMode()
|
||||
dn := runconfig.DefaultDaemonNetworkMode().NetworkName()
|
||||
options = append(options, nwconfig.OptionDefaultDriver(string(dd)))
|
||||
options = append(options, nwconfig.OptionDefaultNetwork(dn))
|
||||
}
|
||||
options = append(options, nwconfig.OptionLabels(dconfig.Labels))
|
||||
return options, nil
|
||||
}
|
||||
|
||||
func initNetworkController(config *Config) (libnetwork.NetworkController, error) {
|
||||
controller, err := libnetwork.New()
|
||||
netOptions, err := networkOptions(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
controller, err := libnetwork.New(netOptions...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error obtaining controller instance: %v", err)
|
||||
}
|
||||
@@ -419,3 +449,7 @@ func setupInitLayer(initLayer string) error {
|
||||
// Layer is ready to use, if it wasn't before.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) NetworkApiRouter() func(w http.ResponseWriter, req *http.Request) {
|
||||
return nwapi.NewHTTPHandler(daemon.netController)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user