2014-08-09 18:30:27 -04:00
package daemon
2013-10-04 22:25:15 -04:00
import (
2014-08-09 21:18:32 -04:00
"github.com/docker/docker/daemon/networkdriver"
2015-04-04 00:06:48 -04:00
"github.com/docker/docker/daemon/networkdriver/bridge"
2014-08-09 21:18:32 -04:00
"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"
2015-02-04 14:04:58 -05:00
"github.com/docker/docker/runconfig"
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 {
2015-04-04 00:06:48 -04:00
Bridge bridge . Config
Pidfile string
Root string
AutoRestart bool
Dns [ ] string
DnsSearch [ ] string
GraphDriver string
GraphOptions [ ] string
ExecDriver string
Mtu int
SocketGroup string
EnableCors bool
CorsHeaders string
DisableNetwork bool
EnableSelinuxSupport bool
Context map [ string ] [ ] string
TrustKeyPath string
Labels [ ] string
Ulimits map [ string ] * ulimit . Ulimit
LogConfig runconfig . LogConfig
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-04-04 00:06:48 -04:00
flag . BoolVar ( & config . Bridge . EnableIptables , [ ] string { "#iptables" , "-iptables" } , true , "Enable addition of iptables rules" )
flag . BoolVar ( & config . Bridge . EnableIpForward , [ ] string { "#ip-forward" , "-ip-forward" } , true , "Enable net.ipv4.ip_forward" )
flag . BoolVar ( & config . Bridge . EnableIpMasq , [ ] string { "-ip-masq" } , true , "Enable IP masquerading" )
flag . BoolVar ( & config . Bridge . EnableIPv6 , [ ] string { "-ipv6" } , false , "Enable IPv6 networking" )
flag . StringVar ( & config . Bridge . IP , [ ] string { "#bip" , "-bip" } , "" , "Specify network bridge IP" )
flag . StringVar ( & config . Bridge . Iface , [ ] string { "b" , "-bridge" } , "" , "Attach containers to a network bridge" )
flag . StringVar ( & config . Bridge . FixedCIDR , [ ] string { "-fixed-cidr" } , "" , "IPv4 subnet for fixed IPs" )
flag . StringVar ( & config . Bridge . FixedCIDRv6 , [ ] string { "-fixed-cidr-v6" } , "" , "IPv6 subnet for fixed IPs" )
flag . BoolVar ( & config . Bridge . InterContainerCommunication , [ ] string { "#icc" , "-icc" } , true , "Enable inter-container communication" )
2015-02-03 22:51:35 -05:00
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-04-04 00:06:48 -04:00
opts . IPVar ( & config . Bridge . 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" )
2015-04-08 19:37:39 -04:00
flag . StringVar ( & config . LogConfig . Type , [ ] string { "-log-driver" } , "json-file" , "Default driver for container logs" )
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
}