1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add -bip flag: allow specification of dynamic bridge IP via CIDR

e.g.:

```
docker -d -bip "10.10.0.1/16"
```

If set and valid, use provided in place of trial and error from pre-defined array in network.go.
Mutually exclusive of -b option.
This commit is contained in:
WarheadsSE 2013-12-13 10:47:19 -05:00
parent fb9ddc5de5
commit a68d7f3d70
4 changed files with 30 additions and 12 deletions

View file

@ -14,6 +14,7 @@ type DaemonConfig struct {
Dns []string Dns []string
EnableIptables bool EnableIptables bool
BridgeIface string BridgeIface string
BridgeIp string
DefaultIp net.IP DefaultIp net.IP
InterContainerCommunication bool InterContainerCommunication bool
GraphDriver string GraphDriver string
@ -36,6 +37,7 @@ func ConfigFromJob(job *engine.Job) *DaemonConfig {
} else { } else {
config.BridgeIface = DefaultNetworkBridge config.BridgeIface = DefaultNetworkBridge
} }
config.BridgeIp = job.Getenv("BridgeIp")
config.DefaultIp = net.ParseIP(job.Getenv("DefaultIp")) config.DefaultIp = net.ParseIP(job.Getenv("DefaultIp"))
config.InterContainerCommunication = job.GetenvBool("InterContainerCommunication") config.InterContainerCommunication = job.GetenvBool("InterContainerCommunication")
config.GraphDriver = job.Getenv("GraphDriver") config.GraphDriver = job.Getenv("GraphDriver")

View file

@ -30,6 +30,7 @@ func main() {
flDebug = flag.Bool("D", false, "Enable debug mode") flDebug = flag.Bool("D", false, "Enable debug mode")
flAutoRestart = flag.Bool("r", true, "Restart previously running containers") 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") 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") 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") 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") 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)) 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 { if *flDebug {
os.Setenv("DEBUG", "1") os.Setenv("DEBUG", "1")
} }
@ -77,6 +82,7 @@ func main() {
job.SetenvList("Dns", flDns.GetAll()) job.SetenvList("Dns", flDns.GetAll())
job.SetenvBool("EnableIptables", *flEnableIptables) job.SetenvBool("EnableIptables", *flEnableIptables)
job.Setenv("BridgeIface", *bridgeName) job.Setenv("BridgeIface", *bridgeName)
job.Setenv("BridgeIp", *bridgeIp)
job.Setenv("DefaultIp", *flDefaultIp) job.Setenv("DefaultIp", *flDefaultIp)
job.SetenvBool("InterContainerCommunication", *flInterContainerComm) job.SetenvBool("InterContainerCommunication", *flInterContainerComm)
job.Setenv("GraphDriver", *flGraphDriver) job.Setenv("GraphDriver", *flGraphDriver)

View file

@ -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 -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 -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 -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 -d=false: Enable daemon mode
-dns="": Force docker to use specific DNS servers -dns="": Force docker to use specific DNS servers
-g="/var/lib/docker": Path to use as the root of the docker runtime -g="/var/lib/docker": Path to use as the root of the docker runtime

View file

@ -118,6 +118,7 @@ func CreateBridgeIface(config *DaemonConfig) error {
"192.168.44.1/24", "192.168.44.1/24",
} }
nameservers := []string{} nameservers := []string{}
resolvConf, _ := utils.GetResolvConf() resolvConf, _ := utils.GetResolvConf()
// we don't check for an error here, because we don't really care // 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 var ifaceAddr string
for _, addr := range addrs { if len(config.BridgeIp) != 0 {
_, dockerNetwork, err := net.ParseCIDR(addr) _, _, err := net.ParseCIDR(config.BridgeIp)
if err != nil { if err != nil {
return err return err
} }
routes, err := netlink.NetworkGetRoutes() ifaceAddr = config.BridgeIp
if err != nil { } else {
return err for _, addr := range addrs {
} _, dockerNetwork, err := net.ParseCIDR(addr)
if err := checkRouteOverlaps(routes, dockerNetwork); err == nil { if err != nil {
if err := checkNameserverOverlaps(nameservers, dockerNetwork); err == nil { return err
ifaceAddr = addr }
break 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 == "" { if ifaceAddr == "" {