config_common_unix.go 3.4 KB

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