config.go 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package main
  2. import (
  3. "github.com/docker/docker/daemon/config"
  4. "github.com/docker/docker/opts"
  5. "github.com/spf13/pflag"
  6. )
  7. const (
  8. // defaultShutdownTimeout is the default shutdown timeout for the daemon
  9. defaultShutdownTimeout = 15
  10. // defaultTrustKeyFile is the default filename for the trust key
  11. defaultTrustKeyFile = "key.json"
  12. )
  13. // installCommonConfigFlags adds flags to the pflag.FlagSet to configure the daemon
  14. func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
  15. var maxConcurrentDownloads, maxConcurrentUploads int
  16. conf.ServiceOptions.InstallCliFlags(flags)
  17. flags.Var(opts.NewNamedListOptsRef("storage-opts", &conf.GraphOptions, nil), "storage-opt", "Storage driver options")
  18. flags.Var(opts.NewNamedListOptsRef("authorization-plugins", &conf.AuthorizationPlugins, nil), "authorization-plugin", "Authorization plugins to load")
  19. flags.Var(opts.NewNamedListOptsRef("exec-opts", &conf.ExecOptions, nil), "exec-opt", "Runtime execution options")
  20. flags.StringVarP(&conf.Pidfile, "pidfile", "p", defaultPidFile, "Path to use for daemon PID file")
  21. flags.StringVarP(&conf.Root, "graph", "g", defaultDataRoot, "Root of the Docker runtime")
  22. // "--graph" is "soft-deprecated" in favor of "data-root". This flag was added
  23. // before Docker 1.0, so won't be removed, only hidden, to discourage its usage.
  24. flags.MarkHidden("graph")
  25. flags.StringVar(&conf.Root, "data-root", defaultDataRoot, "Root directory of persistent Docker state")
  26. flags.BoolVarP(&conf.AutoRestart, "restart", "r", true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
  27. flags.MarkDeprecated("restart", "Please use a restart policy on docker run")
  28. flags.StringVarP(&conf.GraphDriver, "storage-driver", "s", "", "Storage driver to use")
  29. flags.IntVar(&conf.Mtu, "mtu", 0, "Set the containers network MTU")
  30. flags.BoolVar(&conf.RawLogs, "raw-logs", false, "Full timestamps without ANSI coloring")
  31. flags.Var(opts.NewListOptsRef(&conf.DNS, opts.ValidateIPAddress), "dns", "DNS server to use")
  32. flags.Var(opts.NewNamedListOptsRef("dns-opts", &conf.DNSOptions, nil), "dns-opt", "DNS options to use")
  33. flags.Var(opts.NewListOptsRef(&conf.DNSSearch, opts.ValidateDNSSearch), "dns-search", "DNS search domains to use")
  34. flags.Var(opts.NewNamedListOptsRef("labels", &conf.Labels, opts.ValidateLabel), "label", "Set key=value labels to the daemon")
  35. flags.StringVar(&conf.LogConfig.Type, "log-driver", "json-file", "Default driver for container logs")
  36. flags.Var(opts.NewNamedMapOpts("log-opts", conf.LogConfig.Config, nil), "log-opt", "Default log driver options for containers")
  37. flags.StringVar(&conf.ClusterAdvertise, "cluster-advertise", "", "Address or interface name to advertise")
  38. flags.StringVar(&conf.ClusterStore, "cluster-store", "", "URL of the distributed storage backend")
  39. flags.Var(opts.NewNamedMapOpts("cluster-store-opts", conf.ClusterOpts, nil), "cluster-store-opt", "Set cluster store options")
  40. flags.StringVar(&conf.CorsHeaders, "api-cors-header", "", "Set CORS headers in the Engine API")
  41. flags.IntVar(&maxConcurrentDownloads, "max-concurrent-downloads", config.DefaultMaxConcurrentDownloads, "Set the max concurrent downloads for each pull")
  42. flags.IntVar(&maxConcurrentUploads, "max-concurrent-uploads", config.DefaultMaxConcurrentUploads, "Set the max concurrent uploads for each push")
  43. flags.IntVar(&conf.ShutdownTimeout, "shutdown-timeout", defaultShutdownTimeout, "Set the default shutdown timeout")
  44. flags.StringVar(&conf.SwarmDefaultAdvertiseAddr, "swarm-default-advertise-addr", "", "Set default address or interface for swarm advertised address")
  45. flags.BoolVar(&conf.Experimental, "experimental", false, "Enable experimental features")
  46. flags.StringVar(&conf.MetricsAddress, "metrics-addr", "", "Set default address and port to serve the metrics api on")
  47. // "--deprecated-key-path" is to allow configuration of the key used
  48. // for the daemon ID and the deprecated image signing. It was never
  49. // exposed as a command line option but is added here to allow
  50. // overriding the default path in configuration.
  51. flags.Var(opts.NewQuotedString(&conf.TrustKeyPath), "deprecated-key-path", "Path to key file for ID and image signing")
  52. flags.MarkHidden("deprecated-key-path")
  53. conf.MaxConcurrentDownloads = &maxConcurrentDownloads
  54. conf.MaxConcurrentUploads = &maxConcurrentUploads
  55. }