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