Windows: factor out bridgeConfig from server+config
| ... | ... |
@@ -36,7 +36,6 @@ import ( |
| 36 | 36 |
"github.com/docker/docker/pkg/version" |
| 37 | 37 |
"github.com/docker/docker/runconfig" |
| 38 | 38 |
"github.com/docker/docker/utils" |
| 39 |
- "github.com/docker/libnetwork/portallocator" |
|
| 40 | 39 |
) |
| 41 | 40 |
|
| 42 | 41 |
type ServerConfig struct {
|
| ... | ... |
@@ -1546,30 +1545,3 @@ func createRouter(s *Server) *mux.Router {
|
| 1546 | 1546 |
|
| 1547 | 1547 |
return r |
| 1548 | 1548 |
} |
| 1549 |
- |
|
| 1550 |
-func allocateDaemonPort(addr string) error {
|
|
| 1551 |
- host, port, err := net.SplitHostPort(addr) |
|
| 1552 |
- if err != nil {
|
|
| 1553 |
- return err |
|
| 1554 |
- } |
|
| 1555 |
- |
|
| 1556 |
- intPort, err := strconv.Atoi(port) |
|
| 1557 |
- if err != nil {
|
|
| 1558 |
- return err |
|
| 1559 |
- } |
|
| 1560 |
- |
|
| 1561 |
- var hostIPs []net.IP |
|
| 1562 |
- if parsedIP := net.ParseIP(host); parsedIP != nil {
|
|
| 1563 |
- hostIPs = append(hostIPs, parsedIP) |
|
| 1564 |
- } else if hostIPs, err = net.LookupIP(host); err != nil {
|
|
| 1565 |
- return fmt.Errorf("failed to lookup %s address in host specification", host)
|
|
| 1566 |
- } |
|
| 1567 |
- |
|
| 1568 |
- pa := portallocator.Get() |
|
| 1569 |
- for _, hostIP := range hostIPs {
|
|
| 1570 |
- if _, err := pa.RequestPort(hostIP, "tcp", intPort); err != nil {
|
|
| 1571 |
- return fmt.Errorf("failed to allocate daemon listening port %d (err: %v)", intPort, err)
|
|
| 1572 |
- } |
|
| 1573 |
- } |
|
| 1574 |
- return nil |
|
| 1575 |
-} |
| ... | ... |
@@ -6,10 +6,12 @@ import ( |
| 6 | 6 |
"fmt" |
| 7 | 7 |
"net" |
| 8 | 8 |
"net/http" |
| 9 |
+ "strconv" |
|
| 9 | 10 |
|
| 10 | 11 |
"github.com/docker/docker/daemon" |
| 11 | 12 |
"github.com/docker/docker/pkg/sockets" |
| 12 | 13 |
"github.com/docker/docker/pkg/systemd" |
| 14 |
+ "github.com/docker/libnetwork/portallocator" |
|
| 13 | 15 |
) |
| 14 | 16 |
|
| 15 | 17 |
// newServer sets up the required serverCloser and does protocol specific checking. |
| ... | ... |
@@ -76,3 +78,30 @@ func (s *Server) AcceptConnections(d *daemon.Daemon) {
|
| 76 | 76 |
close(s.start) |
| 77 | 77 |
} |
| 78 | 78 |
} |
| 79 |
+ |
|
| 80 |
+func allocateDaemonPort(addr string) error {
|
|
| 81 |
+ host, port, err := net.SplitHostPort(addr) |
|
| 82 |
+ if err != nil {
|
|
| 83 |
+ return err |
|
| 84 |
+ } |
|
| 85 |
+ |
|
| 86 |
+ intPort, err := strconv.Atoi(port) |
|
| 87 |
+ if err != nil {
|
|
| 88 |
+ return err |
|
| 89 |
+ } |
|
| 90 |
+ |
|
| 91 |
+ var hostIPs []net.IP |
|
| 92 |
+ if parsedIP := net.ParseIP(host); parsedIP != nil {
|
|
| 93 |
+ hostIPs = append(hostIPs, parsedIP) |
|
| 94 |
+ } else if hostIPs, err = net.LookupIP(host); err != nil {
|
|
| 95 |
+ return fmt.Errorf("failed to lookup %s address in host specification", host)
|
|
| 96 |
+ } |
|
| 97 |
+ |
|
| 98 |
+ pa := portallocator.Get() |
|
| 99 |
+ for _, hostIP := range hostIPs {
|
|
| 100 |
+ if _, err := pa.RequestPort(hostIP, "tcp", intPort); err != nil {
|
|
| 101 |
+ return fmt.Errorf("failed to allocate daemon listening port %d (err: %v)", intPort, err)
|
|
| 102 |
+ } |
|
| 103 |
+ } |
|
| 104 |
+ return nil |
|
| 105 |
+} |
| ... | ... |
@@ -11,7 +11,7 @@ import ( |
| 11 | 11 |
) |
| 12 | 12 |
|
| 13 | 13 |
// NewServer sets up the required Server and does protocol specific checking. |
| 14 |
-func (s *Server) newServer(proto, addr string) (Server, error) {
|
|
| 14 |
+func (s *Server) newServer(proto, addr string) (serverCloser, error) {
|
|
| 15 | 15 |
var ( |
| 16 | 16 |
err error |
| 17 | 17 |
l net.Listener |
| ... | ... |
@@ -22,6 +22,7 @@ func (s *Server) newServer(proto, addr string) (Server, error) {
|
| 22 | 22 |
if err != nil {
|
| 23 | 23 |
return nil, err |
| 24 | 24 |
} |
| 25 |
+ |
|
| 25 | 26 |
default: |
| 26 | 27 |
return nil, errors.New("Invalid protocol format. Windows only supports tcp.")
|
| 27 | 28 |
} |
| ... | ... |
@@ -43,3 +44,7 @@ func (s *Server) AcceptConnections(d *daemon.Daemon) {
|
| 43 | 43 |
close(s.start) |
| 44 | 44 |
} |
| 45 | 45 |
} |
| 46 |
+ |
|
| 47 |
+func allocateDaemonPort(addr string) error {
|
|
| 48 |
+ return nil |
|
| 49 |
+} |
| ... | ... |
@@ -1,8 +1,6 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "net" |
|
| 5 |
- |
|
| 6 | 4 |
"github.com/docker/docker/opts" |
| 7 | 5 |
flag "github.com/docker/docker/pkg/mflag" |
| 8 | 6 |
"github.com/docker/docker/runconfig" |
| ... | ... |
@@ -16,9 +14,7 @@ const ( |
| 16 | 16 |
// CommonConfig defines the configuration of a docker daemon which are |
| 17 | 17 |
// common across platforms. |
| 18 | 18 |
type CommonConfig struct {
|
| 19 |
- AutoRestart bool |
|
| 20 |
- // Bridge holds bridge network specific configuration. |
|
| 21 |
- Bridge bridgeConfig |
|
| 19 |
+ AutoRestart bool |
|
| 22 | 20 |
Context map[string][]string |
| 23 | 21 |
CorsHeaders string |
| 24 | 22 |
DisableNetwork bool |
| ... | ... |
@@ -26,8 +22,10 @@ type CommonConfig struct {
|
| 26 | 26 |
DnsSearch []string |
| 27 | 27 |
EnableCors bool |
| 28 | 28 |
ExecDriver string |
| 29 |
+ ExecOptions []string |
|
| 29 | 30 |
ExecRoot string |
| 30 | 31 |
GraphDriver string |
| 32 |
+ GraphOptions []string |
|
| 31 | 33 |
Labels []string |
| 32 | 34 |
LogConfig runconfig.LogConfig |
| 33 | 35 |
Mtu int |
| ... | ... |
@@ -36,57 +34,26 @@ type CommonConfig struct {
|
| 36 | 36 |
TrustKeyPath string |
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 |
-// bridgeConfig stores all the bridge driver specific |
|
| 40 |
-// configuration. |
|
| 41 |
-type bridgeConfig struct {
|
|
| 42 |
- EnableIPv6 bool |
|
| 43 |
- EnableIPTables bool |
|
| 44 |
- EnableIPForward bool |
|
| 45 |
- EnableIPMasq bool |
|
| 46 |
- EnableUserlandProxy bool |
|
| 47 |
- DefaultIP net.IP |
|
| 48 |
- Iface string |
|
| 49 |
- IP string |
|
| 50 |
- FixedCIDR string |
|
| 51 |
- FixedCIDRv6 string |
|
| 52 |
- DefaultGatewayIPv4 string |
|
| 53 |
- DefaultGatewayIPv6 string |
|
| 54 |
- InterContainerCommunication bool |
|
| 55 |
-} |
|
| 56 |
- |
|
| 57 | 39 |
// InstallCommonFlags adds command-line options to the top-level flag parser for |
| 58 | 40 |
// the current process. |
| 59 | 41 |
// Subsequent calls to `flag.Parse` will populate config with values parsed |
| 60 | 42 |
// from the command-line. |
| 61 |
- |
|
| 62 | 43 |
func (config *Config) InstallCommonFlags() {
|
| 44 |
+ opts.ListVar(&config.GraphOptions, []string{"-storage-opt"}, "Set storage driver options")
|
|
| 45 |
+ opts.ListVar(&config.ExecOptions, []string{"-exec-opt"}, "Set exec driver options")
|
|
| 63 | 46 |
flag.StringVar(&config.Pidfile, []string{"p", "-pidfile"}, defaultPidFile, "Path to use for daemon PID file")
|
| 64 | 47 |
flag.StringVar(&config.Root, []string{"g", "-graph"}, defaultGraph, "Root of the Docker runtime")
|
| 65 | 48 |
flag.StringVar(&config.ExecRoot, []string{"-exec-root"}, "/var/run/docker", "Root of the Docker execdriver")
|
| 66 | 49 |
flag.BoolVar(&config.AutoRestart, []string{"#r", "#-restart"}, true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
|
| 67 |
- flag.BoolVar(&config.Bridge.EnableIPTables, []string{"#iptables", "-iptables"}, true, "Enable addition of iptables rules")
|
|
| 68 |
- flag.BoolVar(&config.Bridge.EnableIPForward, []string{"#ip-forward", "-ip-forward"}, true, "Enable net.ipv4.ip_forward")
|
|
| 69 |
- flag.BoolVar(&config.Bridge.EnableIPMasq, []string{"-ip-masq"}, true, "Enable IP masquerading")
|
|
| 70 |
- flag.BoolVar(&config.Bridge.EnableIPv6, []string{"-ipv6"}, false, "Enable IPv6 networking")
|
|
| 71 |
- flag.StringVar(&config.Bridge.IP, []string{"#bip", "-bip"}, "", "Specify network bridge IP")
|
|
| 72 |
- flag.StringVar(&config.Bridge.Iface, []string{"b", "-bridge"}, "", "Attach containers to a network bridge")
|
|
| 73 |
- flag.StringVar(&config.Bridge.FixedCIDR, []string{"-fixed-cidr"}, "", "IPv4 subnet for fixed IPs")
|
|
| 74 |
- flag.StringVar(&config.Bridge.FixedCIDRv6, []string{"-fixed-cidr-v6"}, "", "IPv6 subnet for fixed IPs")
|
|
| 75 |
- flag.StringVar(&config.Bridge.DefaultGatewayIPv4, []string{"-default-gateway"}, "", "Container default gateway IPv4 address")
|
|
| 76 |
- flag.StringVar(&config.Bridge.DefaultGatewayIPv6, []string{"-default-gateway-v6"}, "", "Container default gateway IPv6 address")
|
|
| 77 |
- flag.BoolVar(&config.Bridge.InterContainerCommunication, []string{"#icc", "-icc"}, true, "Enable inter-container communication")
|
|
| 78 | 50 |
flag.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", "Storage driver to use")
|
| 79 | 51 |
flag.StringVar(&config.ExecDriver, []string{"e", "-exec-driver"}, defaultExec, "Exec driver to use")
|
| 80 | 52 |
flag.IntVar(&config.Mtu, []string{"#mtu", "-mtu"}, 0, "Set the containers network MTU")
|
| 81 | 53 |
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")
|
| 82 | 54 |
flag.StringVar(&config.CorsHeaders, []string{"-api-cors-header"}, "", "Set CORS headers in the remote API")
|
| 83 |
- opts.IPVar(&config.Bridge.DefaultIP, []string{"#ip", "-ip"}, "0.0.0.0", "Default IP when binding container ports")
|
|
| 84 | 55 |
// FIXME: why the inconsistency between "hosts" and "sockets"? |
| 85 | 56 |
opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "DNS server to use")
|
| 86 | 57 |
opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "DNS search domains to use")
|
| 87 | 58 |
opts.LabelListVar(&config.Labels, []string{"-label"}, "Set key=value labels to the daemon")
|
| 88 | 59 |
flag.StringVar(&config.LogConfig.Type, []string{"-log-driver"}, "json-file", "Default driver for container logs")
|
| 89 | 60 |
opts.LogOptsVar(config.LogConfig.Config, []string{"-log-opt"}, "Set log driver options")
|
| 90 |
- flag.BoolVar(&config.Bridge.EnableUserlandProxy, []string{"-userland-proxy"}, true, "Use userland proxy for loopback traffic")
|
|
| 91 |
- |
|
| 92 | 61 |
} |
| ... | ... |
@@ -1,6 +1,8 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "net" |
|
| 5 |
+ |
|
| 4 | 6 |
"github.com/docker/docker/opts" |
| 5 | 7 |
flag "github.com/docker/docker/pkg/mflag" |
| 6 | 8 |
"github.com/docker/docker/pkg/ulimit" |
| ... | ... |
@@ -19,13 +21,32 @@ type Config struct {
|
| 19 | 19 |
CommonConfig |
| 20 | 20 |
|
| 21 | 21 |
// Fields below here are platform specific. |
| 22 |
+ |
|
| 23 |
+ // Bridge holds bridge network specific configuration. |
|
| 24 |
+ Bridge bridgeConfig |
|
| 22 | 25 |
EnableSelinuxSupport bool |
| 23 |
- ExecOptions []string |
|
| 24 |
- GraphOptions []string |
|
| 25 | 26 |
SocketGroup string |
| 26 | 27 |
Ulimits map[string]*ulimit.Ulimit |
| 27 | 28 |
} |
| 28 | 29 |
|
| 30 |
+// bridgeConfig stores all the bridge driver specific |
|
| 31 |
+// configuration. |
|
| 32 |
+type bridgeConfig struct {
|
|
| 33 |
+ EnableIPv6 bool |
|
| 34 |
+ EnableIPTables bool |
|
| 35 |
+ EnableIPForward bool |
|
| 36 |
+ EnableIPMasq bool |
|
| 37 |
+ EnableUserlandProxy bool |
|
| 38 |
+ DefaultIP net.IP |
|
| 39 |
+ Iface string |
|
| 40 |
+ IP string |
|
| 41 |
+ FixedCIDR string |
|
| 42 |
+ FixedCIDRv6 string |
|
| 43 |
+ DefaultGatewayIPv4 string |
|
| 44 |
+ DefaultGatewayIPv6 string |
|
| 45 |
+ InterContainerCommunication bool |
|
| 46 |
+} |
|
| 47 |
+ |
|
| 29 | 48 |
// InstallFlags adds command-line options to the top-level flag parser for |
| 30 | 49 |
// the current process. |
| 31 | 50 |
// Subsequent calls to `flag.Parse` will populate config with values parsed |
| ... | ... |
@@ -35,10 +56,21 @@ func (config *Config) InstallFlags() {
|
| 35 | 35 |
config.InstallCommonFlags() |
| 36 | 36 |
|
| 37 | 37 |
// Then platform-specific install flags |
| 38 |
- opts.ListVar(&config.GraphOptions, []string{"-storage-opt"}, "Set storage driver options")
|
|
| 39 |
- opts.ListVar(&config.ExecOptions, []string{"-exec-opt"}, "Set exec driver options")
|
|
| 40 | 38 |
flag.BoolVar(&config.EnableSelinuxSupport, []string{"-selinux-enabled"}, false, "Enable selinux support")
|
| 41 | 39 |
flag.StringVar(&config.SocketGroup, []string{"G", "-group"}, "docker", "Group for the unix socket")
|
| 42 | 40 |
config.Ulimits = make(map[string]*ulimit.Ulimit) |
| 43 | 41 |
opts.UlimitMapVar(config.Ulimits, []string{"-default-ulimit"}, "Set default ulimits for containers")
|
| 42 |
+ flag.BoolVar(&config.Bridge.EnableIPTables, []string{"#iptables", "-iptables"}, true, "Enable addition of iptables rules")
|
|
| 43 |
+ flag.BoolVar(&config.Bridge.EnableIPForward, []string{"#ip-forward", "-ip-forward"}, true, "Enable net.ipv4.ip_forward")
|
|
| 44 |
+ flag.BoolVar(&config.Bridge.EnableIPMasq, []string{"-ip-masq"}, true, "Enable IP masquerading")
|
|
| 45 |
+ flag.BoolVar(&config.Bridge.EnableIPv6, []string{"-ipv6"}, false, "Enable IPv6 networking")
|
|
| 46 |
+ flag.StringVar(&config.Bridge.IP, []string{"#bip", "-bip"}, "", "Specify network bridge IP")
|
|
| 47 |
+ flag.StringVar(&config.Bridge.Iface, []string{"b", "-bridge"}, "", "Attach containers to a network bridge")
|
|
| 48 |
+ flag.StringVar(&config.Bridge.FixedCIDR, []string{"-fixed-cidr"}, "", "IPv4 subnet for fixed IPs")
|
|
| 49 |
+ flag.StringVar(&config.Bridge.FixedCIDRv6, []string{"-fixed-cidr-v6"}, "", "IPv6 subnet for fixed IPs")
|
|
| 50 |
+ flag.StringVar(&config.Bridge.DefaultGatewayIPv4, []string{"-default-gateway"}, "", "Container default gateway IPv4 address")
|
|
| 51 |
+ flag.StringVar(&config.Bridge.DefaultGatewayIPv6, []string{"-default-gateway-v6"}, "", "Container default gateway IPv6 address")
|
|
| 52 |
+ flag.BoolVar(&config.Bridge.InterContainerCommunication, []string{"#icc", "-icc"}, true, "Enable inter-container communication")
|
|
| 53 |
+ opts.IPVar(&config.Bridge.DefaultIP, []string{"#ip", "-ip"}, "0.0.0.0", "Default IP when binding container ports")
|
|
| 54 |
+ flag.BoolVar(&config.Bridge.EnableUserlandProxy, []string{"-userland-proxy"}, true, "Use userland proxy for loopback traffic")
|
|
| 44 | 55 |
} |