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"
2015-02-11 14:21:38 -05:00
"github.com/docker/docker/pkg/ulimit"
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
2015-01-08 18:03:19 -05:00
EnableIPv6 bool
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
2014-05-28 16:06:23 -04:00
FixedCIDR string
2015-01-08 18:03:19 -05:00
FixedCIDRv6 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
2015-01-29 21:55:22 -05:00
SocketGroup string
EnableCors bool
2015-02-09 02:15:07 -05:00
CorsHeaders string
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
2014-11-17 14:23:41 -05:00
TrustKeyPath string
2014-11-20 13:36:05 -05:00
Labels [ ] string
2015-02-11 14:21:38 -05:00
Ulimits map [ string ] * ulimit . Ulimit
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" )
2015-02-03 22:51:35 -05:00
flag . StringVar ( & config . Root , [ ] string { "g" , "-graph" } , "/var/lib/docker" , "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" )
2015-02-03 22:51:35 -05:00
flag . BoolVar ( & config . EnableIptables , [ ] string { "#iptables" , "-iptables" } , true , "Enable addition of iptables rules" )
flag . BoolVar ( & config . EnableIpForward , [ ] string { "#ip-forward" , "-ip-forward" } , true , "Enable net.ipv4.ip_forward" )
flag . BoolVar ( & config . EnableIpMasq , [ ] string { "-ip-masq" } , true , "Enable IP masquerading" )
2015-01-08 18:03:19 -05:00
flag . BoolVar ( & config . EnableIPv6 , [ ] string { "-ipv6" } , false , "Enable IPv6 networking" )
2015-02-03 22:51:35 -05:00
flag . StringVar ( & config . BridgeIP , [ ] string { "#bip" , "-bip" } , "" , "Specify network bridge IP" )
flag . StringVar ( & config . BridgeIface , [ ] string { "b" , "-bridge" } , "" , "Attach containers to a network bridge" )
flag . StringVar ( & config . FixedCIDR , [ ] string { "-fixed-cidr" } , "" , "IPv4 subnet for fixed IPs" )
flag . StringVar ( & config . FixedCIDRv6 , [ ] string { "-fixed-cidr-v6" } , "" , "IPv6 subnet for fixed IPs" )
flag . BoolVar ( & config . InterContainerCommunication , [ ] string { "#icc" , "-icc" } , true , "Enable inter-container communication" )
flag . StringVar ( & config . GraphDriver , [ ] string { "s" , "-storage-driver" } , "" , "Storage driver to use" )
flag . StringVar ( & config . ExecDriver , [ ] string { "e" , "-exec-driver" } , "native" , "Exec driver to use" )
flag . BoolVar ( & config . EnableSelinuxSupport , [ ] string { "-selinux-enabled" } , false , "Enable selinux support" )
flag . IntVar ( & config . Mtu , [ ] string { "#mtu" , "-mtu" } , 0 , "Set the containers network MTU" )
2015-01-29 21:55:22 -05:00
flag . StringVar ( & config . SocketGroup , [ ] string { "G" , "-group" } , "docker" , "Group for the unix socket" )
2015-02-27 00:38:16 -05:00
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" )
2015-02-09 02:15:07 -05:00
flag . StringVar ( & config . CorsHeaders , [ ] string { "-api-cors-header" } , "" , "Set CORS headers in the remote API" )
2015-02-03 22:51:35 -05:00
opts . IPVar ( & config . DefaultIp , [ ] string { "#ip" , "-ip" } , "0.0.0.0" , "Default IP when binding container ports" )
2014-08-09 21:18:32 -04:00
opts . ListVar ( & config . GraphOptions , [ ] string { "-storage-opt" } , "Set storage driver options" )
// FIXME: why the inconsistency between "hosts" and "sockets"?
2015-02-03 22:51:35 -05:00
opts . IPListVar ( & config . Dns , [ ] string { "#dns" , "-dns" } , "DNS server to use" )
opts . DnsSearchListVar ( & config . DnsSearch , [ ] string { "-dns-search" } , "DNS search domains to use" )
opts . LabelListVar ( & config . Labels , [ ] string { "-label" } , "Set key=value labels to the daemon" )
2015-02-11 14:21:38 -05:00
config . Ulimits = make ( map [ string ] * ulimit . Ulimit )
opts . UlimitMapVar ( config . Ulimits , [ ] string { "-default-ulimit" } , "Set default ulimits for containers" )
2014-08-09 21:18:32 -04:00
}
2014-11-04 18:53:34 -05:00
func getDefaultNetworkMtu ( ) int {
2014-02-01 06:38:39 -05:00
if iface , err := networkdriver . GetDefaultRouteIface ( ) ; err == nil {
return iface . MTU
}
return defaultNetworkMtu
}