github.com/gdevillele/moby@v1.13.0/daemon/config_common_unix.go (about)

     1  // +build solaris linux freebsd
     2  
     3  package daemon
     4  
     5  import (
     6  	"net"
     7  
     8  	"github.com/docker/docker/api/types"
     9  	"github.com/docker/docker/opts"
    10  	runconfigopts "github.com/docker/docker/runconfig/opts"
    11  	"github.com/spf13/pflag"
    12  )
    13  
    14  // CommonUnixConfig defines configuration of a docker daemon that is
    15  // common across Unix platforms.
    16  type CommonUnixConfig struct {
    17  	ExecRoot       string                   `json:"exec-root,omitempty"`
    18  	ContainerdAddr string                   `json:"containerd,omitempty"`
    19  	Runtimes       map[string]types.Runtime `json:"runtimes,omitempty"`
    20  	DefaultRuntime string                   `json:"default-runtime,omitempty"`
    21  }
    22  
    23  type commonUnixBridgeConfig struct {
    24  	DefaultIP                   net.IP `json:"ip,omitempty"`
    25  	IP                          string `json:"bip,omitempty"`
    26  	DefaultGatewayIPv4          net.IP `json:"default-gateway,omitempty"`
    27  	DefaultGatewayIPv6          net.IP `json:"default-gateway-v6,omitempty"`
    28  	InterContainerCommunication bool   `json:"icc,omitempty"`
    29  }
    30  
    31  // InstallCommonUnixFlags adds command-line options to the top-level flag parser for
    32  // the current process that are common across Unix platforms.
    33  func (config *Config) InstallCommonUnixFlags(flags *pflag.FlagSet) {
    34  	config.Runtimes = make(map[string]types.Runtime)
    35  
    36  	flags.StringVarP(&config.SocketGroup, "group", "G", "docker", "Group for the unix socket")
    37  	flags.StringVar(&config.bridgeConfig.IP, "bip", "", "Specify network bridge IP")
    38  	flags.StringVarP(&config.bridgeConfig.Iface, "bridge", "b", "", "Attach containers to a network bridge")
    39  	flags.StringVar(&config.bridgeConfig.FixedCIDR, "fixed-cidr", "", "IPv4 subnet for fixed IPs")
    40  	flags.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultGatewayIPv4, ""), "default-gateway", "Container default gateway IPv4 address")
    41  	flags.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultGatewayIPv6, ""), "default-gateway-v6", "Container default gateway IPv6 address")
    42  	flags.BoolVar(&config.bridgeConfig.InterContainerCommunication, "icc", true, "Enable inter-container communication")
    43  	flags.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultIP, "0.0.0.0"), "ip", "Default IP when binding container ports")
    44  	flags.Var(runconfigopts.NewNamedRuntimeOpt("runtimes", &config.Runtimes, stockRuntimeName), "add-runtime", "Register an additional OCI compatible runtime")
    45  	flags.StringVar(&config.DefaultRuntime, "default-runtime", stockRuntimeName, "Default OCI runtime for containers")
    46  
    47  }
    48  
    49  // GetRuntime returns the runtime path and arguments for a given
    50  // runtime name
    51  func (config *Config) GetRuntime(name string) *types.Runtime {
    52  	config.reloadLock.Lock()
    53  	defer config.reloadLock.Unlock()
    54  	if rt, ok := config.Runtimes[name]; ok {
    55  		return &rt
    56  	}
    57  	return nil
    58  }
    59  
    60  // GetDefaultRuntimeName returns the current default runtime
    61  func (config *Config) GetDefaultRuntimeName() string {
    62  	config.reloadLock.Lock()
    63  	rt := config.DefaultRuntime
    64  	config.reloadLock.Unlock()
    65  
    66  	return rt
    67  }
    68  
    69  // GetAllRuntimes returns a copy of the runtimes map
    70  func (config *Config) GetAllRuntimes() map[string]types.Runtime {
    71  	config.reloadLock.Lock()
    72  	rts := config.Runtimes
    73  	config.reloadLock.Unlock()
    74  	return rts
    75  }
    76  
    77  // GetExecRoot returns the user configured Exec-root
    78  func (config *Config) GetExecRoot() string {
    79  	return config.ExecRoot
    80  }
    81  
    82  // GetInitPath returns the configure docker-init path
    83  func (config *Config) GetInitPath() string {
    84  	config.reloadLock.Lock()
    85  	defer config.reloadLock.Unlock()
    86  	if config.InitPath != "" {
    87  		return config.InitPath
    88  	}
    89  	return DefaultInitBinary
    90  }