github.com/niusmallnan/moby@v1.13.1/daemon/config_unix.go (about)

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