config.go 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. EnableIptables bool
  23. EnableIpForward bool
  24. DefaultIp net.IP
  25. BridgeIface string
  26. BridgeIP string
  27. InterContainerCommunication bool
  28. GraphDriver string
  29. GraphOptions []string
  30. ExecDriver string
  31. Mtu int
  32. DisableNetwork bool
  33. EnableSelinuxSupport bool
  34. Context map[string][]string
  35. }
  36. // InstallFlags adds command-line options to the top-level flag parser for
  37. // the current process.
  38. // Subsequent calls to `flag.Parse` will populate config with values parsed
  39. // from the command-line.
  40. func (config *Config) InstallFlags() {
  41. flag.StringVar(&config.Pidfile, []string{"p", "-pidfile"}, "/var/run/docker.pid", "Path to use for daemon PID file")
  42. flag.StringVar(&config.Root, []string{"g", "-graph"}, "/var/lib/docker", "Path to use as the root of the Docker runtime")
  43. flag.BoolVar(&config.AutoRestart, []string{"r", "-restart"}, true, "Restart previously running containers")
  44. flag.BoolVar(&config.EnableIptables, []string{"#iptables", "-iptables"}, true, "Enable Docker's addition of iptables rules")
  45. flag.BoolVar(&config.EnableIpForward, []string{"#ip-forward", "-ip-forward"}, true, "Enable net.ipv4.ip_forward")
  46. flag.StringVar(&config.BridgeIP, []string{"#bip", "-bip"}, "", "Use this CIDR notation address for the network bridge's IP, not compatible with -b")
  47. flag.StringVar(&config.BridgeIface, []string{"b", "-bridge"}, "", "Attach containers to a pre-existing network bridge\nuse 'none' to disable container networking")
  48. flag.BoolVar(&config.InterContainerCommunication, []string{"#icc", "-icc"}, true, "Enable inter-container communication")
  49. flag.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", "Force the Docker runtime to use a specific storage driver")
  50. flag.StringVar(&config.ExecDriver, []string{"e", "-exec-driver"}, "native", "Force the Docker runtime to use a specific exec driver")
  51. flag.BoolVar(&config.EnableSelinuxSupport, []string{"-selinux-enabled"}, false, "Enable selinux support. SELinux does not presently support the BTRFS storage driver")
  52. 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")
  53. opts.IPVar(&config.DefaultIp, []string{"#ip", "-ip"}, "0.0.0.0", "Default IP address to use when binding container ports")
  54. opts.ListVar(&config.GraphOptions, []string{"-storage-opt"}, "Set storage driver options")
  55. // FIXME: why the inconsistency between "hosts" and "sockets"?
  56. opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "Force Docker to use specific DNS servers")
  57. opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "Force Docker to use specific DNS search domains")
  58. }
  59. func GetDefaultNetworkMtu() int {
  60. if iface, err := networkdriver.GetDefaultRouteIface(); err == nil {
  61. return iface.MTU
  62. }
  63. return defaultNetworkMtu
  64. }