diff --git a/config.go b/config.go index 51d435b841..1f743f6290 100644 --- a/config.go +++ b/config.go @@ -14,6 +14,7 @@ type DaemonConfig struct { Dns []string EnableIptables bool BridgeIface string + BridgeIp string DefaultIp net.IP InterContainerCommunication bool GraphDriver string @@ -36,6 +37,7 @@ func ConfigFromJob(job *engine.Job) *DaemonConfig { } else { config.BridgeIface = DefaultNetworkBridge } + config.BridgeIp = job.Getenv("BridgeIp") config.DefaultIp = net.ParseIP(job.Getenv("DefaultIp")) config.InterContainerCommunication = job.GetenvBool("InterContainerCommunication") config.GraphDriver = job.Getenv("GraphDriver") diff --git a/docker/docker.go b/docker/docker.go index 6e243f157f..3ee7be9876 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -30,6 +30,7 @@ func main() { flDebug = flag.Bool("D", false, "Enable debug mode") flAutoRestart = flag.Bool("r", true, "Restart previously running containers") bridgeName = flag.String("b", "", "Attach containers to a pre-existing network bridge; use 'none' to disable container networking") + bridgeIp = flag.String("bip", "", "Use this CIDR notation address for the network bridge's IP, not compatible with -b") pidfile = flag.String("p", "/var/run/docker.pid", "Path to use for daemon PID file") flRoot = flag.String("g", "/var/lib/docker", "Path to use as the root of the docker runtime") flEnableCors = flag.Bool("api-enable-cors", false, "Enable CORS headers in the remote API") @@ -54,6 +55,10 @@ func main() { flHosts.Set(fmt.Sprintf("unix://%s", docker.DEFAULTUNIXSOCKET)) } + if *bridgeName != "" && *bridgeIp != "" { + log.Fatal("You specified -b & -bip, mutually exclusive options. Please specify only one.") + } + if *flDebug { os.Setenv("DEBUG", "1") } @@ -77,6 +82,7 @@ func main() { job.SetenvList("Dns", flDns.GetAll()) job.SetenvBool("EnableIptables", *flEnableIptables) job.Setenv("BridgeIface", *bridgeName) + job.Setenv("BridgeIp", *bridgeIp) job.Setenv("DefaultIp", *flDefaultIp) job.SetenvBool("InterContainerCommunication", *flInterContainerComm) job.Setenv("GraphDriver", *flGraphDriver) diff --git a/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index 5cbd28c951..68d18b58bf 100644 --- a/docs/sources/commandline/cli.rst +++ b/docs/sources/commandline/cli.rst @@ -30,6 +30,7 @@ To list available commands, either run ``docker`` with no parameters or execute -H=[unix:///var/run/docker.sock]: Multiple tcp://host:port or unix://path/to/socket to bind in daemon mode, single connection otherwise -api-enable-cors=false: Enable CORS headers in the remote API -b="": Attach containers to a pre-existing network bridge; use 'none' to disable container networking + -bip="": Use the provided CIDR notation address for the dynamically created bridge (docker0); Mutually exclusive of -b -d=false: Enable daemon mode -dns="": Force docker to use specific DNS servers -g="/var/lib/docker": Path to use as the root of the docker runtime diff --git a/network.go b/network.go index a230356a7d..7999826da1 100644 --- a/network.go +++ b/network.go @@ -118,6 +118,7 @@ func CreateBridgeIface(config *DaemonConfig) error { "192.168.44.1/24", } + nameservers := []string{} resolvConf, _ := utils.GetResolvConf() // we don't check for an error here, because we don't really care @@ -129,22 +130,30 @@ func CreateBridgeIface(config *DaemonConfig) error { } var ifaceAddr string - for _, addr := range addrs { - _, dockerNetwork, err := net.ParseCIDR(addr) + if len(config.BridgeIp) != 0 { + _, _, err := net.ParseCIDR(config.BridgeIp) if err != nil { return err } - routes, err := netlink.NetworkGetRoutes() - if err != nil { - return err - } - if err := checkRouteOverlaps(routes, dockerNetwork); err == nil { - if err := checkNameserverOverlaps(nameservers, dockerNetwork); err == nil { - ifaceAddr = addr - break + ifaceAddr = config.BridgeIp + } else { + for _, addr := range addrs { + _, dockerNetwork, err := net.ParseCIDR(addr) + if err != nil { + return err + } + routes, err := netlink.NetworkGetRoutes() + if err != nil { + return err + } + if err := checkRouteOverlaps(routes, dockerNetwork); err == nil { + if err := checkNameserverOverlaps(nameservers, dockerNetwork); err == nil { + ifaceAddr = addr + break + } + } else { + utils.Debugf("%s: %s", addr, err) } - } else { - utils.Debugf("%s: %s", addr, err) } } if ifaceAddr == "" {