config.go 4.8 KB

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