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