2014-08-09 22:30:27 +00:00
package daemon
2013-10-05 02:25:15 +00:00
import (
2014-04-02 17:56:30 +00:00
"net"
2014-08-10 01:18:32 +00:00
"github.com/docker/docker/daemon/networkdriver"
"github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag"
2013-10-05 02:25:15 +00:00
)
2014-01-30 02:34:43 +00:00
const (
2014-02-01 11:38:39 +00:00
defaultNetworkMtu = 1500
2014-09-16 17:37:50 +00:00
disableNetworkBridge = "none"
2014-01-30 02:34:43 +00:00
)
2014-08-09 22:30:27 +00:00
// Config define the configuration of a docker daemon
2014-08-10 01:18:32 +00:00
// These are the configuration settings that you pass
2014-08-09 22:30:27 +00:00
// to the docker daemon when you launch it with say: `docker -d -e lxc`
2013-10-21 16:04:42 +00:00
// FIXME: separate runtime configuration from http api configuration
2014-03-07 23:22:23 +00:00
type Config struct {
2013-10-10 20:48:22 +00:00
Pidfile string
2013-10-23 08:09:16 +00:00
Root string
2013-10-10 20:48:22 +00:00
AutoRestart bool
Dns [ ] string
2014-02-07 16:48:14 +00:00
DnsSearch [ ] string
2014-07-18 18:48:19 +00:00
Mirrors [ ] string
2013-10-10 20:48:22 +00:00
EnableIptables bool
2014-01-28 04:35:05 +00:00
EnableIpForward bool
2014-09-17 03:00:15 +00:00
EnableIpMasq bool
2013-10-10 20:48:22 +00:00
DefaultIp net . IP
2014-01-30 02:34:43 +00:00
BridgeIface string
BridgeIP string
2013-10-10 20:48:22 +00:00
InterContainerCommunication bool
2013-11-15 07:02:09 +00:00
GraphDriver string
2014-06-05 08:34:20 +00:00
GraphOptions [ ] string
2014-02-17 21:54:36 +00:00
ExecDriver string
2013-12-19 23:16:54 +00:00
Mtu int
2014-01-30 02:34:43 +00:00
DisableNetwork bool
2014-04-07 21:43:50 +00:00
EnableSelinuxSupport bool
2014-04-17 23:47:27 +00:00
Context map [ string ] [ ] string
2013-10-05 02:25:15 +00:00
}
2013-10-21 16:04:42 +00:00
2014-08-10 01:18:32 +00:00
// InstallFlags adds command-line options to the top-level flag parser for
// the current process.
// Subsequent calls to `flag.Parse` will populate config with values parsed
// from the command-line.
func ( config * Config ) InstallFlags ( ) {
flag . StringVar ( & config . Pidfile , [ ] string { "p" , "-pidfile" } , "/var/run/docker.pid" , "Path to use for daemon PID file" )
flag . StringVar ( & config . Root , [ ] string { "g" , "-graph" } , "/var/lib/docker" , "Path to use as the root of the Docker runtime" )
2014-08-22 19:56:43 +00:00
flag . BoolVar ( & config . AutoRestart , [ ] string { "#r" , "#-restart" } , true , "--restart on the daemon has been deprecated in favor of --restart policies on docker run" )
2014-08-10 01:18:32 +00:00
flag . BoolVar ( & config . EnableIptables , [ ] string { "#iptables" , "-iptables" } , true , "Enable Docker's addition of iptables rules" )
flag . BoolVar ( & config . EnableIpForward , [ ] string { "#ip-forward" , "-ip-forward" } , true , "Enable net.ipv4.ip_forward" )
2014-09-17 03:00:15 +00:00
flag . BoolVar ( & config . EnableIpMasq , [ ] string { "-ip-masq" } , true , "Enable IP masquerading for bridge's IP range" )
2014-08-10 01:18:32 +00:00
flag . StringVar ( & config . BridgeIP , [ ] string { "#bip" , "-bip" } , "" , "Use this CIDR notation address for the network bridge's IP, not compatible with -b" )
flag . StringVar ( & config . BridgeIface , [ ] string { "b" , "-bridge" } , "" , "Attach containers to a pre-existing network bridge\nuse 'none' to disable container networking" )
flag . BoolVar ( & config . InterContainerCommunication , [ ] string { "#icc" , "-icc" } , true , "Enable inter-container communication" )
flag . StringVar ( & config . GraphDriver , [ ] string { "s" , "-storage-driver" } , "" , "Force the Docker runtime to use a specific storage driver" )
flag . StringVar ( & config . ExecDriver , [ ] string { "e" , "-exec-driver" } , "native" , "Force the Docker runtime to use a specific exec driver" )
flag . BoolVar ( & config . EnableSelinuxSupport , [ ] string { "-selinux-enabled" } , false , "Enable selinux support. SELinux does not presently support the BTRFS storage driver" )
flag . IntVar ( & config . Mtu , [ ] string { "#mtu" , "-mtu" } , 0 , "Set the containers network MTU\nif no value is provided: default to the default route MTU or 1500 if no default route is available" )
opts . IPVar ( & config . DefaultIp , [ ] string { "#ip" , "-ip" } , "0.0.0.0" , "Default IP address to use when binding container ports" )
opts . ListVar ( & config . GraphOptions , [ ] string { "-storage-opt" } , "Set storage driver options" )
// FIXME: why the inconsistency between "hosts" and "sockets"?
opts . IPListVar ( & config . Dns , [ ] string { "#dns" , "-dns" } , "Force Docker to use specific DNS servers" )
opts . DnsSearchListVar ( & config . DnsSearch , [ ] string { "-dns-search" } , "Force Docker to use specific DNS search domains" )
2014-07-18 18:48:19 +00:00
opts . MirrorListVar ( & config . Mirrors , [ ] string { "-registry-mirror" } , "Specify a preferred Docker registry mirror" )
2014-08-10 01:18:32 +00:00
}
2014-02-01 11:38:39 +00:00
func GetDefaultNetworkMtu ( ) int {
if iface , err := networkdriver . GetDefaultRouteIface ( ) ; err == nil {
return iface . MTU
}
return defaultNetworkMtu
}