config_unix.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // +build linux freebsd
  2. package daemon
  3. import (
  4. "net"
  5. "github.com/docker/docker/opts"
  6. flag "github.com/docker/docker/pkg/mflag"
  7. runconfigopts "github.com/docker/docker/runconfig/opts"
  8. "github.com/docker/go-units"
  9. )
  10. var (
  11. defaultPidFile = "/var/run/docker.pid"
  12. defaultGraph = "/var/lib/docker"
  13. defaultExec = "native"
  14. )
  15. // Config defines the configuration of a docker daemon.
  16. // It includes json tags to deserialize configuration from a file
  17. // using the same names that the flags in the command line uses.
  18. type Config struct {
  19. CommonConfig
  20. // Fields below here are platform specific.
  21. CorsHeaders string `json:"api-cors-headers,omitempty"`
  22. EnableCors bool `json:"api-enable-cors,omitempty"`
  23. EnableSelinuxSupport bool `json:"selinux-enabled,omitempty"`
  24. RemappedRoot string `json:"userns-remap,omitempty"`
  25. SocketGroup string `json:"group,omitempty"`
  26. CgroupParent string `json:"cgroup-parent,omitempty"`
  27. Ulimits map[string]*units.Ulimit `json:"default-ulimits,omitempty"`
  28. }
  29. // bridgeConfig stores all the bridge driver specific
  30. // configuration.
  31. type bridgeConfig struct {
  32. EnableIPv6 bool
  33. EnableIPTables bool
  34. EnableIPForward bool
  35. EnableIPMasq bool
  36. EnableUserlandProxy bool
  37. DefaultIP net.IP
  38. Iface string
  39. IP string
  40. FixedCIDR string
  41. FixedCIDRv6 string
  42. DefaultGatewayIPv4 net.IP
  43. DefaultGatewayIPv6 net.IP
  44. InterContainerCommunication bool
  45. }
  46. // InstallFlags adds command-line options to the top-level flag parser for
  47. // the current process.
  48. // Subsequent calls to `flag.Parse` will populate config with values parsed
  49. // from the command-line.
  50. func (config *Config) InstallFlags(cmd *flag.FlagSet, usageFn func(string) string) {
  51. // First handle install flags which are consistent cross-platform
  52. config.InstallCommonFlags(cmd, usageFn)
  53. // Then platform-specific install flags
  54. cmd.BoolVar(&config.EnableSelinuxSupport, []string{"-selinux-enabled"}, false, usageFn("Enable selinux support"))
  55. cmd.StringVar(&config.SocketGroup, []string{"G", "-group"}, "docker", usageFn("Group for the unix socket"))
  56. config.Ulimits = make(map[string]*units.Ulimit)
  57. cmd.Var(runconfigopts.NewUlimitOpt(&config.Ulimits), []string{"-default-ulimit"}, usageFn("Set default ulimits for containers"))
  58. cmd.BoolVar(&config.Bridge.EnableIPTables, []string{"#iptables", "-iptables"}, true, usageFn("Enable addition of iptables rules"))
  59. cmd.BoolVar(&config.Bridge.EnableIPForward, []string{"#ip-forward", "-ip-forward"}, true, usageFn("Enable net.ipv4.ip_forward"))
  60. cmd.BoolVar(&config.Bridge.EnableIPMasq, []string{"-ip-masq"}, true, usageFn("Enable IP masquerading"))
  61. cmd.BoolVar(&config.Bridge.EnableIPv6, []string{"-ipv6"}, false, usageFn("Enable IPv6 networking"))
  62. cmd.StringVar(&config.Bridge.IP, []string{"#bip", "-bip"}, "", usageFn("Specify network bridge IP"))
  63. cmd.StringVar(&config.Bridge.Iface, []string{"b", "-bridge"}, "", usageFn("Attach containers to a network bridge"))
  64. cmd.StringVar(&config.Bridge.FixedCIDR, []string{"-fixed-cidr"}, "", usageFn("IPv4 subnet for fixed IPs"))
  65. cmd.StringVar(&config.Bridge.FixedCIDRv6, []string{"-fixed-cidr-v6"}, "", usageFn("IPv6 subnet for fixed IPs"))
  66. cmd.Var(opts.NewIPOpt(&config.Bridge.DefaultGatewayIPv4, ""), []string{"-default-gateway"}, usageFn("Container default gateway IPv4 address"))
  67. cmd.Var(opts.NewIPOpt(&config.Bridge.DefaultGatewayIPv6, ""), []string{"-default-gateway-v6"}, usageFn("Container default gateway IPv6 address"))
  68. cmd.BoolVar(&config.Bridge.InterContainerCommunication, []string{"#icc", "-icc"}, true, usageFn("Enable inter-container communication"))
  69. cmd.Var(opts.NewIPOpt(&config.Bridge.DefaultIP, "0.0.0.0"), []string{"#ip", "-ip"}, usageFn("Default IP when binding container ports"))
  70. cmd.BoolVar(&config.Bridge.EnableUserlandProxy, []string{"-userland-proxy"}, true, usageFn("Use userland proxy for loopback traffic"))
  71. cmd.BoolVar(&config.EnableCors, []string{"#api-enable-cors", "#-api-enable-cors"}, false, usageFn("Enable CORS headers in the remote API, this is deprecated by --api-cors-header"))
  72. cmd.StringVar(&config.CorsHeaders, []string{"-api-cors-header"}, "", usageFn("Set CORS headers in the remote API"))
  73. cmd.StringVar(&config.CgroupParent, []string{"-cgroup-parent"}, "", usageFn("Set parent cgroup for all containers"))
  74. cmd.StringVar(&config.RemappedRoot, []string{"-userns-remap"}, "", usageFn("User/Group setting for user namespaces"))
  75. config.attachExperimentalFlags(cmd, usageFn)
  76. }