config.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package daemon
  2. import (
  3. "github.com/docker/docker/opts"
  4. flag "github.com/docker/docker/pkg/mflag"
  5. "github.com/docker/docker/runconfig"
  6. )
  7. const (
  8. defaultNetworkMtu = 1500
  9. disableNetworkBridge = "none"
  10. )
  11. // CommonConfig defines the configuration of a docker daemon which are
  12. // common across platforms.
  13. type CommonConfig struct {
  14. AutoRestart bool
  15. Context map[string][]string
  16. CorsHeaders string
  17. DisableNetwork bool
  18. Dns []string
  19. DnsSearch []string
  20. EnableCors bool
  21. ExecDriver string
  22. ExecOptions []string
  23. ExecRoot string
  24. GraphDriver string
  25. GraphOptions []string
  26. Labels []string
  27. LogConfig runconfig.LogConfig
  28. Mtu int
  29. Pidfile string
  30. Root string
  31. TrustKeyPath string
  32. DefaultNetwork string
  33. NetworkKVStore string
  34. }
  35. // InstallCommonFlags adds command-line options to the top-level flag parser for
  36. // the current process.
  37. // Subsequent calls to `flag.Parse` will populate config with values parsed
  38. // from the command-line.
  39. func (config *Config) InstallCommonFlags() {
  40. opts.ListVar(&config.GraphOptions, []string{"-storage-opt"}, "Set storage driver options")
  41. opts.ListVar(&config.ExecOptions, []string{"-exec-opt"}, "Set exec driver options")
  42. flag.StringVar(&config.Pidfile, []string{"p", "-pidfile"}, defaultPidFile, "Path to use for daemon PID file")
  43. flag.StringVar(&config.Root, []string{"g", "-graph"}, defaultGraph, "Root of the Docker runtime")
  44. flag.StringVar(&config.ExecRoot, []string{"-exec-root"}, "/var/run/docker", "Root of the Docker execdriver")
  45. flag.BoolVar(&config.AutoRestart, []string{"#r", "#-restart"}, true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
  46. flag.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", "Storage driver to use")
  47. flag.StringVar(&config.ExecDriver, []string{"e", "-exec-driver"}, defaultExec, "Exec driver to use")
  48. flag.IntVar(&config.Mtu, []string{"#mtu", "-mtu"}, 0, "Set the containers network MTU")
  49. flag.BoolVar(&config.EnableCors, []string{"#api-enable-cors", "#-api-enable-cors"}, false, "Enable CORS headers in the remote API, this is deprecated by --api-cors-header")
  50. flag.StringVar(&config.CorsHeaders, []string{"-api-cors-header"}, "", "Set CORS headers in the remote API")
  51. // FIXME: why the inconsistency between "hosts" and "sockets"?
  52. opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "DNS server to use")
  53. opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "DNS search domains to use")
  54. opts.LabelListVar(&config.Labels, []string{"-label"}, "Set key=value labels to the daemon")
  55. flag.StringVar(&config.LogConfig.Type, []string{"-log-driver"}, "json-file", "Default driver for container logs")
  56. opts.LogOptsVar(config.LogConfig.Config, []string{"-log-opt"}, "Set log driver options")
  57. }