config_unix.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. // DefaultIpcMode is default for container's IpcMode, if not set otherwise
  11. DefaultIpcMode = "private"
  12. )
  13. // Config defines the configuration of a docker daemon.
  14. // It includes json tags to deserialize configuration from a file
  15. // using the same names that the flags in the command line uses.
  16. type Config struct {
  17. CommonConfig
  18. // These fields are common to all unix platforms.
  19. CommonUnixConfig
  20. // Fields below here are platform specific.
  21. CgroupParent string `json:"cgroup-parent,omitempty"`
  22. EnableSelinuxSupport bool `json:"selinux-enabled,omitempty"`
  23. RemappedRoot string `json:"userns-remap,omitempty"`
  24. Ulimits map[string]*units.Ulimit `json:"default-ulimits,omitempty"`
  25. CPURealtimePeriod int64 `json:"cpu-rt-period,omitempty"`
  26. CPURealtimeRuntime int64 `json:"cpu-rt-runtime,omitempty"`
  27. OOMScoreAdjust int `json:"oom-score-adjust,omitempty"`
  28. Init bool `json:"init,omitempty"`
  29. InitPath string `json:"init-path,omitempty"`
  30. SeccompProfile string `json:"seccomp-profile,omitempty"`
  31. ShmSize opts.MemBytes `json:"default-shm-size,omitempty"`
  32. NoNewPrivileges bool `json:"no-new-privileges,omitempty"`
  33. IpcMode string `json:"default-ipc-mode,omitempty"`
  34. CgroupNamespaceMode string `json:"default-cgroupns-mode,omitempty"`
  35. // ResolvConf is the path to the configuration of the host resolver
  36. ResolvConf string `json:"resolv-conf,omitempty"`
  37. Rootless bool `json:"rootless,omitempty"`
  38. }
  39. // BridgeConfig stores all the bridge driver specific
  40. // configuration.
  41. type BridgeConfig struct {
  42. commonBridgeConfig
  43. // These fields are common to all unix platforms.
  44. commonUnixBridgeConfig
  45. // Fields below here are platform specific.
  46. EnableIPv6 bool `json:"ipv6,omitempty"`
  47. EnableIPTables bool `json:"iptables,omitempty"`
  48. EnableIP6Tables bool `json:"ip6tables,omitempty"`
  49. EnableIPForward bool `json:"ip-forward,omitempty"`
  50. EnableIPMasq bool `json:"ip-masq,omitempty"`
  51. EnableUserlandProxy bool `json:"userland-proxy,omitempty"`
  52. UserlandProxyPath string `json:"userland-proxy-path,omitempty"`
  53. FixedCIDRv6 string `json:"fixed-cidr-v6,omitempty"`
  54. }
  55. // IsSwarmCompatible defines if swarm mode can be enabled in this config
  56. func (conf *Config) IsSwarmCompatible() error {
  57. if conf.ClusterStore != "" || conf.ClusterAdvertise != "" {
  58. return fmt.Errorf("--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
  59. }
  60. if conf.LiveRestoreEnabled {
  61. return fmt.Errorf("--live-restore daemon configuration is incompatible with swarm mode")
  62. }
  63. return nil
  64. }
  65. func verifyDefaultIpcMode(mode string) error {
  66. const hint = `use "shareable" or "private"`
  67. dm := containertypes.IpcMode(mode)
  68. if !dm.Valid() {
  69. return fmt.Errorf("default IPC mode setting (%v) is invalid; "+hint, dm)
  70. }
  71. if dm != "" && !dm.IsPrivate() && !dm.IsShareable() {
  72. return fmt.Errorf(`IPC mode "%v" is not supported as default value; `+hint, dm)
  73. }
  74. return nil
  75. }
  76. func verifyDefaultCgroupNsMode(mode string) error {
  77. cm := containertypes.CgroupnsMode(mode)
  78. if !cm.Valid() {
  79. return fmt.Errorf(`default cgroup namespace mode (%v) is invalid; use "host" or "private"`, cm)
  80. }
  81. return nil
  82. }
  83. // ValidatePlatformConfig checks if any platform-specific configuration settings are invalid.
  84. func (conf *Config) ValidatePlatformConfig() error {
  85. if err := verifyDefaultIpcMode(conf.IpcMode); err != nil {
  86. return err
  87. }
  88. return verifyDefaultCgroupNsMode(conf.CgroupNamespaceMode)
  89. }
  90. // IsRootless returns conf.Rootless
  91. func (conf *Config) IsRootless() bool {
  92. return conf.Rootless
  93. }