2015-07-29 18:25:56 +00:00
|
|
|
// +build linux freebsd
|
|
|
|
|
2015-04-24 22:36:11 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2016-06-14 16:13:53 +00:00
|
|
|
"fmt"
|
2015-05-15 20:05:35 +00:00
|
|
|
"net"
|
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2015-04-24 22:36:11 +00:00
|
|
|
"github.com/docker/docker/opts"
|
2015-12-21 20:06:46 +00:00
|
|
|
runconfigopts "github.com/docker/docker/runconfig/opts"
|
2016-06-21 20:42:47 +00:00
|
|
|
units "github.com/docker/go-units"
|
|
|
|
"github.com/spf13/pflag"
|
2015-04-24 22:36:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-03-18 18:50:19 +00:00
|
|
|
defaultPidFile = "/var/run/docker.pid"
|
|
|
|
defaultGraph = "/var/lib/docker"
|
|
|
|
defaultExecRoot = "/var/run/docker"
|
2015-04-24 22:36:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config defines the configuration of a docker daemon.
|
2015-12-10 23:35:10 +00:00
|
|
|
// It includes json tags to deserialize configuration from a file
|
|
|
|
// using the same names that the flags in the command line uses.
|
2015-04-24 22:36:11 +00:00
|
|
|
type Config struct {
|
|
|
|
CommonConfig
|
|
|
|
|
|
|
|
// Fields below here are platform specific.
|
2016-03-24 18:42:03 +00:00
|
|
|
CgroupParent string `json:"cgroup-parent,omitempty"`
|
|
|
|
ContainerdAddr string `json:"containerd,omitempty"`
|
2015-12-10 23:35:10 +00:00
|
|
|
EnableSelinuxSupport bool `json:"selinux-enabled,omitempty"`
|
2016-03-24 18:42:03 +00:00
|
|
|
ExecRoot string `json:"exec-root,omitempty"`
|
2015-12-10 23:35:10 +00:00
|
|
|
RemappedRoot string `json:"userns-remap,omitempty"`
|
|
|
|
Ulimits map[string]*units.Ulimit `json:"default-ulimits,omitempty"`
|
2016-05-23 21:49:50 +00:00
|
|
|
Runtimes map[string]types.Runtime `json:"runtimes,omitempty"`
|
|
|
|
DefaultRuntime string `json:"default-runtime,omitempty"`
|
2016-07-11 22:26:23 +00:00
|
|
|
OOMScoreAdjust int `json:"oom-score-adjust,omitempty"`
|
2016-06-27 21:38:47 +00:00
|
|
|
Init bool `json:"init,omitempty"`
|
2016-09-27 10:51:42 +00:00
|
|
|
InitPath string `json:"init-path,omitempty"`
|
2015-04-24 22:36:11 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 20:05:35 +00:00
|
|
|
// bridgeConfig stores all the bridge driver specific
|
|
|
|
// configuration.
|
|
|
|
type bridgeConfig struct {
|
2016-03-28 18:55:20 +00:00
|
|
|
commonBridgeConfig
|
|
|
|
|
|
|
|
// Fields below here are platform specific.
|
2016-01-25 21:30:33 +00:00
|
|
|
EnableIPv6 bool `json:"ipv6,omitempty"`
|
|
|
|
EnableIPTables bool `json:"iptables,omitempty"`
|
|
|
|
EnableIPForward bool `json:"ip-forward,omitempty"`
|
2016-05-16 03:18:48 +00:00
|
|
|
EnableIPMasq bool `json:"ip-masq,omitempty"`
|
2016-01-25 21:30:33 +00:00
|
|
|
EnableUserlandProxy bool `json:"userland-proxy,omitempty"`
|
|
|
|
DefaultIP net.IP `json:"ip,omitempty"`
|
|
|
|
IP string `json:"bip,omitempty"`
|
|
|
|
FixedCIDRv6 string `json:"fixed-cidr-v6,omitempty"`
|
|
|
|
DefaultGatewayIPv4 net.IP `json:"default-gateway,omitempty"`
|
|
|
|
DefaultGatewayIPv6 net.IP `json:"default-gateway-v6,omitempty"`
|
|
|
|
InterContainerCommunication bool `json:"icc,omitempty"`
|
2015-05-15 20:05:35 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 20:42:47 +00:00
|
|
|
// InstallFlags adds flags to the pflag.FlagSet to configure the daemon
|
|
|
|
func (config *Config) InstallFlags(flags *pflag.FlagSet) {
|
2015-04-24 22:36:11 +00:00
|
|
|
// First handle install flags which are consistent cross-platform
|
2016-06-21 20:42:47 +00:00
|
|
|
config.InstallCommonFlags(flags)
|
2015-04-24 22:36:11 +00:00
|
|
|
|
2015-12-21 20:06:46 +00:00
|
|
|
config.Ulimits = make(map[string]*units.Ulimit)
|
2016-05-23 21:49:50 +00:00
|
|
|
config.Runtimes = make(map[string]types.Runtime)
|
2015-10-08 15:51:41 +00:00
|
|
|
|
2016-06-21 20:42:47 +00:00
|
|
|
// Then platform-specific install flags
|
|
|
|
flags.BoolVar(&config.EnableSelinuxSupport, "selinux-enabled", false, "Enable selinux support")
|
2016-08-03 16:20:46 +00:00
|
|
|
flags.StringVarP(&config.SocketGroup, "group", "G", "docker", "Group for the unix socket")
|
2016-06-21 20:42:47 +00:00
|
|
|
flags.Var(runconfigopts.NewUlimitOpt(&config.Ulimits), "default-ulimit", "Default ulimits for containers")
|
|
|
|
flags.BoolVar(&config.bridgeConfig.EnableIPTables, "iptables", true, "Enable addition of iptables rules")
|
|
|
|
flags.BoolVar(&config.bridgeConfig.EnableIPForward, "ip-forward", true, "Enable net.ipv4.ip_forward")
|
|
|
|
flags.BoolVar(&config.bridgeConfig.EnableIPMasq, "ip-masq", true, "Enable IP masquerading")
|
|
|
|
flags.BoolVar(&config.bridgeConfig.EnableIPv6, "ipv6", false, "Enable IPv6 networking")
|
|
|
|
flags.StringVar(&config.ExecRoot, "exec-root", defaultExecRoot, "Root directory for execution state files")
|
|
|
|
flags.StringVar(&config.bridgeConfig.IP, "bip", "", "Specify network bridge IP")
|
|
|
|
flags.StringVarP(&config.bridgeConfig.Iface, "bridge", "b", "", "Attach containers to a network bridge")
|
|
|
|
flags.StringVar(&config.bridgeConfig.FixedCIDR, "fixed-cidr", "", "IPv4 subnet for fixed IPs")
|
|
|
|
flags.StringVar(&config.bridgeConfig.FixedCIDRv6, "fixed-cidr-v6", "", "IPv6 subnet for fixed IPs")
|
|
|
|
flags.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultGatewayIPv4, ""), "default-gateway", "Container default gateway IPv4 address")
|
|
|
|
flags.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultGatewayIPv6, ""), "default-gateway-v6", "Container default gateway IPv6 address")
|
|
|
|
flags.BoolVar(&config.bridgeConfig.InterContainerCommunication, "icc", true, "Enable inter-container communication")
|
|
|
|
flags.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultIP, "0.0.0.0"), "ip", "Default IP when binding container ports")
|
|
|
|
flags.BoolVar(&config.bridgeConfig.EnableUserlandProxy, "userland-proxy", true, "Use userland proxy for loopback traffic")
|
|
|
|
flags.BoolVar(&config.EnableCors, "api-enable-cors", false, "Enable CORS headers in the remote API, this is deprecated by --api-cors-header")
|
|
|
|
flags.MarkDeprecated("api-enable-cors", "Please use --api-cors-header")
|
|
|
|
flags.StringVar(&config.CgroupParent, "cgroup-parent", "", "Set parent cgroup for all containers")
|
|
|
|
flags.StringVar(&config.RemappedRoot, "userns-remap", "", "User/Group setting for user namespaces")
|
|
|
|
flags.StringVar(&config.ContainerdAddr, "containerd", "", "Path to containerd socket")
|
|
|
|
flags.BoolVar(&config.LiveRestoreEnabled, "live-restore", false, "Enable live restore of docker when containers are still running")
|
|
|
|
flags.Var(runconfigopts.NewNamedRuntimeOpt("runtimes", &config.Runtimes, stockRuntimeName), "add-runtime", "Register an additional OCI compatible runtime")
|
|
|
|
flags.StringVar(&config.DefaultRuntime, "default-runtime", stockRuntimeName, "Default OCI runtime for containers")
|
|
|
|
flags.IntVar(&config.OOMScoreAdjust, "oom-score-adjust", -500, "Set the oom_score_adj for the daemon")
|
2016-06-27 21:38:47 +00:00
|
|
|
flags.BoolVar(&config.Init, "init", false, "Run an init in the container to forward signals and reap processes")
|
2016-09-27 10:51:42 +00:00
|
|
|
flags.StringVar(&config.InitPath, "init-path", "", "Path to the docker-init binary")
|
2016-06-21 20:42:47 +00:00
|
|
|
|
|
|
|
config.attachExperimentalFlags(flags)
|
2015-04-24 22:36:11 +00:00
|
|
|
}
|
2016-05-23 21:49:50 +00:00
|
|
|
|
|
|
|
// GetRuntime returns the runtime path and arguments for a given
|
|
|
|
// runtime name
|
|
|
|
func (config *Config) GetRuntime(name string) *types.Runtime {
|
|
|
|
config.reloadLock.Lock()
|
|
|
|
defer config.reloadLock.Unlock()
|
|
|
|
if rt, ok := config.Runtimes[name]; ok {
|
|
|
|
return &rt
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDefaultRuntimeName returns the current default runtime
|
|
|
|
func (config *Config) GetDefaultRuntimeName() string {
|
|
|
|
config.reloadLock.Lock()
|
|
|
|
rt := config.DefaultRuntime
|
|
|
|
config.reloadLock.Unlock()
|
|
|
|
|
|
|
|
return rt
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAllRuntimes returns a copy of the runtimes map
|
|
|
|
func (config *Config) GetAllRuntimes() map[string]types.Runtime {
|
|
|
|
config.reloadLock.Lock()
|
|
|
|
rts := config.Runtimes
|
|
|
|
config.reloadLock.Unlock()
|
|
|
|
return rts
|
|
|
|
}
|
2016-06-14 16:13:53 +00:00
|
|
|
|
2016-07-21 23:13:10 +00:00
|
|
|
// GetExecRoot returns the user configured Exec-root
|
|
|
|
func (config *Config) GetExecRoot() string {
|
|
|
|
return config.ExecRoot
|
|
|
|
}
|
|
|
|
|
2016-06-14 16:13:53 +00:00
|
|
|
func (config *Config) isSwarmCompatible() error {
|
2016-06-28 17:23:35 +00:00
|
|
|
if config.ClusterStore != "" || config.ClusterAdvertise != "" {
|
2016-06-14 16:13:53 +00:00
|
|
|
return fmt.Errorf("--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
|
|
|
|
}
|
2016-07-27 15:30:15 +00:00
|
|
|
if config.LiveRestoreEnabled {
|
2016-06-14 16:13:53 +00:00
|
|
|
return fmt.Errorf("--live-restore daemon configuration is incompatible with swarm mode")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|