config.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. )
  8. const (
  9. defaultNetworkMtu = 1500
  10. disableNetworkBridge = "none"
  11. )
  12. // Config define the configuration of a docker daemon
  13. // These are the configuration settings that you pass
  14. // to the docker daemon when you launch it with say: `docker -d -e lxc`
  15. // FIXME: separate runtime configuration from http api configuration
  16. type Config struct {
  17. Pidfile string
  18. Root string
  19. AutoRestart bool
  20. Dns []string
  21. DnsSearch []string
  22. Mirrors []string
  23. EnableIptables bool
  24. EnableIpForward bool
  25. EnableIpMasq bool
  26. DefaultIp net.IP
  27. BridgeIface string
  28. BridgeIP string
  29. FixedCIDR string
  30. InsecureRegistries []string
  31. InterContainerCommunication bool
  32. GraphDriver string
  33. GraphOptions []string
  34. ExecDriver string
  35. Mtu int
  36. DisableNetwork bool
  37. EnableSelinuxSupport bool
  38. Context map[string][]string
  39. TrustKeyPath string
  40. }
  41. // InstallFlags adds command-line options to the top-level flag parser for
  42. // the current process.
  43. // Subsequent calls to `flag.Parse` will populate config with values parsed
  44. // from the command-line.
  45. func (config *Config) InstallFlags() {
  46. flag.StringVar(&config.Pidfile, []string{"p", "-pidfile"}, "/var/run/docker.pid", "Path to use for daemon PID file")
  47. flag.StringVar(&config.Root, []string{"g", "-graph"}, "/var/lib/docker", "Path to use as the root of the Docker runtime")
  48. flag.BoolVar(&config.AutoRestart, []string{"#r", "#-restart"}, true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
  49. flag.BoolVar(&config.EnableIptables, []string{"#iptables", "-iptables"}, true, "Enable Docker's addition of iptables rules")
  50. flag.BoolVar(&config.EnableIpForward, []string{"#ip-forward", "-ip-forward"}, true, "Enable net.ipv4.ip_forward")
  51. flag.BoolVar(&config.EnableIpMasq, []string{"-ip-masq"}, true, "Enable IP masquerading for bridge's IP range")
  52. flag.StringVar(&config.BridgeIP, []string{"#bip", "-bip"}, "", "Use this CIDR notation address for the network bridge's IP, not compatible with -b")
  53. flag.StringVar(&config.BridgeIface, []string{"b", "-bridge"}, "", "Attach containers to a pre-existing network bridge\nuse 'none' to disable container networking")
  54. flag.StringVar(&config.FixedCIDR, []string{"-fixed-cidr"}, "", "IPv4 subnet for fixed IPs (ex: 10.20.0.0/16)\nthis subnet must be nested in the bridge subnet (which is defined by -b or --bip)")
  55. opts.ListVar(&config.InsecureRegistries, []string{"-insecure-registry"}, "Enable insecure communication with specified registries (no certificate verification for HTTPS and enable HTTP fallback) (e.g., localhost:5000 or 10.20.0.0/16)")
  56. flag.BoolVar(&config.InterContainerCommunication, []string{"#icc", "-icc"}, true, "Enable inter-container communication")
  57. flag.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", "Force the Docker runtime to use a specific storage driver")
  58. flag.StringVar(&config.ExecDriver, []string{"e", "-exec-driver"}, "native", "Force the Docker runtime to use a specific exec driver")
  59. flag.BoolVar(&config.EnableSelinuxSupport, []string{"-selinux-enabled"}, false, "Enable selinux support. SELinux does not presently support the BTRFS storage driver")
  60. 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")
  61. opts.IPVar(&config.DefaultIp, []string{"#ip", "-ip"}, "0.0.0.0", "Default IP address to use when binding container ports")
  62. opts.ListVar(&config.GraphOptions, []string{"-storage-opt"}, "Set storage driver options")
  63. // FIXME: why the inconsistency between "hosts" and "sockets"?
  64. opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "Force Docker to use specific DNS servers")
  65. opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "Force Docker to use specific DNS search domains")
  66. opts.MirrorListVar(&config.Mirrors, []string{"-registry-mirror"}, "Specify a preferred Docker registry mirror")
  67. // Localhost is by default considered as an insecure registry
  68. // This is a stop-gap for people who are running a private registry on localhost (especially on Boot2docker).
  69. //
  70. // TODO: should we deprecate this once it is easier for people to set up a TLS registry or change
  71. // daemon flags on boot2docker?
  72. // If so, do not forget to check the TODO in TestIsSecure
  73. config.InsecureRegistries = append(config.InsecureRegistries, "127.0.0.0/8")
  74. }
  75. func getDefaultNetworkMtu() int {
  76. if iface, err := networkdriver.GetDefaultRouteIface(); err == nil {
  77. return iface.MTU
  78. }
  79. return defaultNetworkMtu
  80. }