github.com/aimxhaisse/docker@v1.6.2/daemon/config.go (about)

     1  package daemon
     2  
     3  import (
     4  	"net"
     5  
     6  	"github.com/docker/docker/daemon/networkdriver"
     7  	"github.com/docker/docker/opts"
     8  	flag "github.com/docker/docker/pkg/mflag"
     9  	"github.com/docker/docker/pkg/ulimit"
    10  	"github.com/docker/docker/runconfig"
    11  )
    12  
    13  const (
    14  	defaultNetworkMtu    = 1500
    15  	disableNetworkBridge = "none"
    16  )
    17  
    18  // Config define the configuration of a docker daemon
    19  // These are the configuration settings that you pass
    20  // to the docker daemon when you launch it with say: `docker -d -e lxc`
    21  // FIXME: separate runtime configuration from http api configuration
    22  type Config struct {
    23  	Pidfile                     string
    24  	Root                        string
    25  	AutoRestart                 bool
    26  	Dns                         []string
    27  	DnsSearch                   []string
    28  	EnableIPv6                  bool
    29  	EnableIptables              bool
    30  	EnableIpForward             bool
    31  	EnableIpMasq                bool
    32  	DefaultIp                   net.IP
    33  	BridgeIface                 string
    34  	BridgeIP                    string
    35  	FixedCIDR                   string
    36  	FixedCIDRv6                 string
    37  	InterContainerCommunication bool
    38  	GraphDriver                 string
    39  	GraphOptions                []string
    40  	ExecDriver                  string
    41  	Mtu                         int
    42  	SocketGroup                 string
    43  	EnableCors                  bool
    44  	CorsHeaders                 string
    45  	DisableNetwork              bool
    46  	EnableSelinuxSupport        bool
    47  	Context                     map[string][]string
    48  	TrustKeyPath                string
    49  	Labels                      []string
    50  	Ulimits                     map[string]*ulimit.Ulimit
    51  	LogConfig                   runconfig.LogConfig
    52  }
    53  
    54  // InstallFlags adds command-line options to the top-level flag parser for
    55  // the current process.
    56  // Subsequent calls to `flag.Parse` will populate config with values parsed
    57  // from the command-line.
    58  func (config *Config) InstallFlags() {
    59  	flag.StringVar(&config.Pidfile, []string{"p", "-pidfile"}, "/var/run/docker.pid", "Path to use for daemon PID file")
    60  	flag.StringVar(&config.Root, []string{"g", "-graph"}, "/var/lib/docker", "Root of the Docker runtime")
    61  	flag.BoolVar(&config.AutoRestart, []string{"#r", "#-restart"}, true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
    62  	flag.BoolVar(&config.EnableIptables, []string{"#iptables", "-iptables"}, true, "Enable addition of iptables rules")
    63  	flag.BoolVar(&config.EnableIpForward, []string{"#ip-forward", "-ip-forward"}, true, "Enable net.ipv4.ip_forward")
    64  	flag.BoolVar(&config.EnableIpMasq, []string{"-ip-masq"}, true, "Enable IP masquerading")
    65  	flag.BoolVar(&config.EnableIPv6, []string{"-ipv6"}, false, "Enable IPv6 networking")
    66  	flag.StringVar(&config.BridgeIP, []string{"#bip", "-bip"}, "", "Specify network bridge IP")
    67  	flag.StringVar(&config.BridgeIface, []string{"b", "-bridge"}, "", "Attach containers to a network bridge")
    68  	flag.StringVar(&config.FixedCIDR, []string{"-fixed-cidr"}, "", "IPv4 subnet for fixed IPs")
    69  	flag.StringVar(&config.FixedCIDRv6, []string{"-fixed-cidr-v6"}, "", "IPv6 subnet for fixed IPs")
    70  	flag.BoolVar(&config.InterContainerCommunication, []string{"#icc", "-icc"}, true, "Enable inter-container communication")
    71  	flag.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", "Storage driver to use")
    72  	flag.StringVar(&config.ExecDriver, []string{"e", "-exec-driver"}, "native", "Exec driver to use")
    73  	flag.BoolVar(&config.EnableSelinuxSupport, []string{"-selinux-enabled"}, false, "Enable selinux support")
    74  	flag.IntVar(&config.Mtu, []string{"#mtu", "-mtu"}, 0, "Set the containers network MTU")
    75  	flag.StringVar(&config.SocketGroup, []string{"G", "-group"}, "docker", "Group for the unix socket")
    76  	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")
    77  	flag.StringVar(&config.CorsHeaders, []string{"-api-cors-header"}, "", "Set CORS headers in the remote API")
    78  	opts.IPVar(&config.DefaultIp, []string{"#ip", "-ip"}, "0.0.0.0", "Default IP when binding container ports")
    79  	opts.ListVar(&config.GraphOptions, []string{"-storage-opt"}, "Set storage driver options")
    80  	// FIXME: why the inconsistency between "hosts" and "sockets"?
    81  	opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "DNS server to use")
    82  	opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "DNS search domains to use")
    83  	opts.LabelListVar(&config.Labels, []string{"-label"}, "Set key=value labels to the daemon")
    84  	config.Ulimits = make(map[string]*ulimit.Ulimit)
    85  	opts.UlimitMapVar(config.Ulimits, []string{"-default-ulimit"}, "Set default ulimits for containers")
    86  	flag.StringVar(&config.LogConfig.Type, []string{"-log-driver"}, "json-file", "Containers logging driver")
    87  }
    88  
    89  func getDefaultNetworkMtu() int {
    90  	if iface, err := networkdriver.GetDefaultRouteIface(); err == nil {
    91  		return iface.MTU
    92  	}
    93  	return defaultNetworkMtu
    94  }