config_unix.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // +build linux freebsd
  2. package daemon
  3. import (
  4. "fmt"
  5. "github.com/docker/docker/opts"
  6. units "github.com/docker/go-units"
  7. "github.com/spf13/pflag"
  8. )
  9. var (
  10. defaultPidFile = "/var/run/docker.pid"
  11. defaultGraph = "/var/lib/docker"
  12. defaultExecRoot = "/var/run/docker"
  13. defaultShmSize = int64(67108864)
  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. // These fields are common to all unix platforms.
  21. CommonUnixConfig
  22. // Fields below here are platform specific.
  23. CgroupParent string `json:"cgroup-parent,omitempty"`
  24. EnableSelinuxSupport bool `json:"selinux-enabled,omitempty"`
  25. RemappedRoot string `json:"userns-remap,omitempty"`
  26. Ulimits map[string]*units.Ulimit `json:"default-ulimits,omitempty"`
  27. CPURealtimePeriod int64 `json:"cpu-rt-period,omitempty"`
  28. CPURealtimeRuntime int64 `json:"cpu-rt-runtime,omitempty"`
  29. OOMScoreAdjust int `json:"oom-score-adjust,omitempty"`
  30. Init bool `json:"init,omitempty"`
  31. InitPath string `json:"init-path,omitempty"`
  32. SeccompProfile string `json:"seccomp-profile,omitempty"`
  33. ShmSize opts.MemBytes `json:"default-shm-size,omitempty"`
  34. }
  35. // bridgeConfig stores all the bridge driver specific
  36. // configuration.
  37. type bridgeConfig struct {
  38. commonBridgeConfig
  39. // These fields are common to all unix platforms.
  40. commonUnixBridgeConfig
  41. // Fields below here are platform specific.
  42. EnableIPv6 bool `json:"ipv6,omitempty"`
  43. EnableIPTables bool `json:"iptables,omitempty"`
  44. EnableIPForward bool `json:"ip-forward,omitempty"`
  45. EnableIPMasq bool `json:"ip-masq,omitempty"`
  46. EnableUserlandProxy bool `json:"userland-proxy,omitempty"`
  47. UserlandProxyPath string `json:"userland-proxy-path,omitempty"`
  48. FixedCIDRv6 string `json:"fixed-cidr-v6,omitempty"`
  49. }
  50. // InstallFlags adds flags to the pflag.FlagSet to configure the daemon
  51. func (config *Config) InstallFlags(flags *pflag.FlagSet) {
  52. // First handle install flags which are consistent cross-platform
  53. config.InstallCommonFlags(flags)
  54. // Then install flags common to unix platforms
  55. config.InstallCommonUnixFlags(flags)
  56. config.Ulimits = make(map[string]*units.Ulimit)
  57. // Set default value for `--default-shm-size`
  58. config.ShmSize = opts.MemBytes(defaultShmSize)
  59. // Then platform-specific install flags
  60. flags.BoolVar(&config.EnableSelinuxSupport, "selinux-enabled", false, "Enable selinux support")
  61. flags.Var(opts.NewUlimitOpt(&config.Ulimits), "default-ulimit", "Default ulimits for containers")
  62. flags.BoolVar(&config.bridgeConfig.EnableIPTables, "iptables", true, "Enable addition of iptables rules")
  63. flags.BoolVar(&config.bridgeConfig.EnableIPForward, "ip-forward", true, "Enable net.ipv4.ip_forward")
  64. flags.BoolVar(&config.bridgeConfig.EnableIPMasq, "ip-masq", true, "Enable IP masquerading")
  65. flags.BoolVar(&config.bridgeConfig.EnableIPv6, "ipv6", false, "Enable IPv6 networking")
  66. flags.StringVar(&config.ExecRoot, "exec-root", defaultExecRoot, "Root directory for execution state files")
  67. flags.StringVar(&config.bridgeConfig.FixedCIDRv6, "fixed-cidr-v6", "", "IPv6 subnet for fixed IPs")
  68. flags.BoolVar(&config.bridgeConfig.EnableUserlandProxy, "userland-proxy", true, "Use userland proxy for loopback traffic")
  69. flags.StringVar(&config.bridgeConfig.UserlandProxyPath, "userland-proxy-path", "", "Path to the userland proxy binary")
  70. flags.BoolVar(&config.EnableCors, "api-enable-cors", false, "Enable CORS headers in the Engine API, this is deprecated by --api-cors-header")
  71. flags.MarkDeprecated("api-enable-cors", "Please use --api-cors-header")
  72. flags.StringVar(&config.CgroupParent, "cgroup-parent", "", "Set parent cgroup for all containers")
  73. flags.StringVar(&config.RemappedRoot, "userns-remap", "", "User/Group setting for user namespaces")
  74. flags.StringVar(&config.ContainerdAddr, "containerd", "", "Path to containerd socket")
  75. flags.BoolVar(&config.LiveRestoreEnabled, "live-restore", false, "Enable live restore of docker when containers are still running")
  76. flags.IntVar(&config.OOMScoreAdjust, "oom-score-adjust", -500, "Set the oom_score_adj for the daemon")
  77. flags.BoolVar(&config.Init, "init", false, "Run an init in the container to forward signals and reap processes")
  78. flags.StringVar(&config.InitPath, "init-path", "", "Path to the docker-init binary")
  79. flags.Int64Var(&config.CPURealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds")
  80. flags.Int64Var(&config.CPURealtimeRuntime, "cpu-rt-runtime", 0, "Limit the CPU real-time runtime in microseconds")
  81. flags.StringVar(&config.SeccompProfile, "seccomp-profile", "", "Path to seccomp profile")
  82. flags.Var(&config.ShmSize, "default-shm-size", "Default shm size for containers")
  83. config.attachExperimentalFlags(flags)
  84. }
  85. func (config *Config) isSwarmCompatible() error {
  86. if config.ClusterStore != "" || config.ClusterAdvertise != "" {
  87. return fmt.Errorf("--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
  88. }
  89. if config.LiveRestoreEnabled {
  90. return fmt.Errorf("--live-restore daemon configuration is incompatible with swarm mode")
  91. }
  92. return nil
  93. }