config_unix.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // +build linux freebsd
  2. package config // import "github.com/docker/docker/daemon/config"
  3. import (
  4. "fmt"
  5. containertypes "github.com/docker/docker/api/types/container"
  6. "github.com/docker/docker/opts"
  7. units "github.com/docker/go-units"
  8. )
  9. const (
  10. // DefaultCgroupNamespaceMode is the default for a container's CgroupnsMode, if not set otherwise
  11. DefaultCgroupNamespaceMode = "host" // TODO: change to private
  12. // DefaultIpcMode is default for container's IpcMode, if not set otherwise
  13. DefaultIpcMode = "private"
  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. NoNewPrivileges bool `json:"no-new-privileges,omitempty"`
  35. IpcMode string `json:"default-ipc-mode,omitempty"`
  36. CgroupNamespaceMode string `json:"default-cgroupns-mode,omitempty"`
  37. // ResolvConf is the path to the configuration of the host resolver
  38. ResolvConf string `json:"resolv-conf,omitempty"`
  39. Rootless bool `json:"rootless,omitempty"`
  40. }
  41. // BridgeConfig stores all the bridge driver specific
  42. // configuration.
  43. type BridgeConfig struct {
  44. commonBridgeConfig
  45. // These fields are common to all unix platforms.
  46. commonUnixBridgeConfig
  47. // Fields below here are platform specific.
  48. EnableIPv6 bool `json:"ipv6,omitempty"`
  49. EnableIPTables bool `json:"iptables,omitempty"`
  50. EnableIPForward bool `json:"ip-forward,omitempty"`
  51. EnableIPMasq bool `json:"ip-masq,omitempty"`
  52. EnableUserlandProxy bool `json:"userland-proxy,omitempty"`
  53. UserlandProxyPath string `json:"userland-proxy-path,omitempty"`
  54. FixedCIDRv6 string `json:"fixed-cidr-v6,omitempty"`
  55. }
  56. // IsSwarmCompatible defines if swarm mode can be enabled in this config
  57. func (conf *Config) IsSwarmCompatible() error {
  58. if conf.ClusterStore != "" || conf.ClusterAdvertise != "" {
  59. return fmt.Errorf("--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
  60. }
  61. if conf.LiveRestoreEnabled {
  62. return fmt.Errorf("--live-restore daemon configuration is incompatible with swarm mode")
  63. }
  64. return nil
  65. }
  66. func verifyDefaultIpcMode(mode string) error {
  67. const hint = "Use \"shareable\" or \"private\"."
  68. dm := containertypes.IpcMode(mode)
  69. if !dm.Valid() {
  70. return fmt.Errorf("Default IPC mode setting (%v) is invalid. "+hint, dm)
  71. }
  72. if dm != "" && !dm.IsPrivate() && !dm.IsShareable() {
  73. return fmt.Errorf("IPC mode \"%v\" is not supported as default value. "+hint, dm)
  74. }
  75. return nil
  76. }
  77. func verifyDefaultCgroupNsMode(mode string) error {
  78. cm := containertypes.CgroupnsMode(mode)
  79. if !cm.Valid() {
  80. return fmt.Errorf("Default cgroup namespace mode (%v) is invalid. Use \"host\" or \"private\".", cm) // nolint: golint
  81. }
  82. return nil
  83. }
  84. // ValidatePlatformConfig checks if any platform-specific configuration settings are invalid.
  85. func (conf *Config) ValidatePlatformConfig() error {
  86. if err := verifyDefaultIpcMode(conf.IpcMode); err != nil {
  87. return err
  88. }
  89. return verifyDefaultCgroupNsMode(conf.CgroupNamespaceMode)
  90. }
  91. // IsRootless returns conf.Rootless
  92. func (conf *Config) IsRootless() bool {
  93. return conf.Rootless
  94. }