2014-08-09 18:30:27 -04:00
package daemon
2013-10-04 22:25:15 -04:00
import (
2014-04-02 13:56:30 -04:00
"net"
2014-08-09 21:18:32 -04:00
"github.com/docker/docker/daemon/networkdriver"
"github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag"
2013-10-04 22:25:15 -04:00
)
2014-01-29 21:34:43 -05:00
const (
2014-02-01 06:38:39 -05:00
defaultNetworkMtu = 1500
2014-09-16 13:37:50 -04:00
disableNetworkBridge = "none"
2014-01-29 21:34:43 -05:00
)
2014-08-09 18:30:27 -04:00
// Config define the configuration of a docker daemon
2014-08-09 21:18:32 -04:00
// These are the configuration settings that you pass
2014-08-09 18:30:27 -04:00
// to the docker daemon when you launch it with say: `docker -d -e lxc`
2013-10-21 12:04:42 -04:00
// FIXME: separate runtime configuration from http api configuration
2014-03-07 18:22:23 -05:00
type Config struct {
2013-10-10 16:48:22 -04:00
Pidfile string
2013-10-23 04:09:16 -04:00
Root string
2013-10-10 16:48:22 -04:00
AutoRestart bool
Dns [ ] string
2014-02-07 11:48:14 -05:00
DnsSearch [ ] string
2014-07-18 14:48:19 -04:00
Mirrors [ ] string
2013-10-10 16:48:22 -04:00
EnableIptables bool
2014-01-27 23:35:05 -05:00
EnableIpForward bool
2014-09-16 23:00:15 -04:00
EnableIpMasq bool
2013-10-10 16:48:22 -04:00
DefaultIp net . IP
2014-01-29 21:34:43 -05:00
BridgeIface string
BridgeIP string
2013-10-10 16:48:22 -04:00
InterContainerCommunication bool
2013-11-15 02:02:09 -05:00
GraphDriver string
2014-06-05 04:34:20 -04:00
GraphOptions [ ] string
2014-02-17 16:54:36 -05:00
ExecDriver string
2013-12-19 18:16:54 -05:00
Mtu int
2014-01-29 21:34:43 -05:00
DisableNetwork bool
2014-04-07 17:43:50 -04:00
EnableSelinuxSupport bool
2014-04-17 19:47:27 -04:00
Context map [ string ] [ ] string
2013-10-04 22:25:15 -04:00
}
2013-10-21 12:04:42 -04:00
2014-08-09 21:18:32 -04: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 15:56:43 -04: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-09 21:18:32 -04: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-16 23:00:15 -04:00
flag . BoolVar ( & config . EnableIpMasq , [ ] string { "-ip-masq" } , true , "Enable IP masquerading for bridge's IP range" )
2014-08-09 21:18:32 -04: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 14:48:19 -04:00
opts . MirrorListVar ( & config . Mirrors , [ ] string { "-registry-mirror" } , "Specify a preferred Docker registry mirror" )
2014-08-09 21:18:32 -04:00
}
2014-02-01 06:38:39 -05:00
func GetDefaultNetworkMtu ( ) int {
if iface , err := networkdriver . GetDefaultRouteIface ( ) ; err == nil {
return iface . MTU
}
return defaultNetworkMtu
}