config_common_unix.go 3.4 KB

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