config_unix.go 3.6 KB

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