config.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package main
  2. import (
  3. "runtime"
  4. "github.com/docker/docker/daemon/config"
  5. "github.com/docker/docker/opts"
  6. "github.com/docker/docker/registry"
  7. "github.com/spf13/pflag"
  8. )
  9. const (
  10. // defaultShutdownTimeout is the default shutdown timeout for the daemon
  11. defaultShutdownTimeout = 15
  12. // defaultTrustKeyFile is the default filename for the trust key
  13. defaultTrustKeyFile = "key.json"
  14. )
  15. // installCommonConfigFlags adds flags to the pflag.FlagSet to configure the daemon
  16. func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
  17. var maxConcurrentDownloads, maxConcurrentUploads int
  18. installRegistryServiceFlags(&conf.ServiceOptions, flags)
  19. flags.Var(opts.NewNamedListOptsRef("storage-opts", &conf.GraphOptions, nil), "storage-opt", "Storage driver options")
  20. flags.Var(opts.NewNamedListOptsRef("authorization-plugins", &conf.AuthorizationPlugins, nil), "authorization-plugin", "Authorization plugins to load")
  21. flags.Var(opts.NewNamedListOptsRef("exec-opts", &conf.ExecOptions, nil), "exec-opt", "Runtime execution options")
  22. flags.StringVarP(&conf.Pidfile, "pidfile", "p", defaultPidFile, "Path to use for daemon PID file")
  23. flags.StringVarP(&conf.Root, "graph", "g", defaultDataRoot, "Root of the Docker runtime")
  24. flags.StringVar(&conf.ExecRoot, "exec-root", defaultExecRoot, "Root directory for execution state files")
  25. flags.StringVar(&conf.ContainerdAddr, "containerd", "", "containerd grpc address")
  26. // "--graph" is "soft-deprecated" in favor of "data-root". This flag was added
  27. // before Docker 1.0, so won't be removed, only hidden, to discourage its usage.
  28. flags.MarkHidden("graph")
  29. flags.StringVar(&conf.Root, "data-root", defaultDataRoot, "Root directory of persistent Docker state")
  30. flags.BoolVarP(&conf.AutoRestart, "restart", "r", true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
  31. flags.MarkDeprecated("restart", "Please use a restart policy on docker run")
  32. // Windows doesn't support setting the storage driver - there is no choice as to which ones to use.
  33. if runtime.GOOS != "windows" {
  34. flags.StringVarP(&conf.GraphDriver, "storage-driver", "s", "", "Storage driver to use")
  35. }
  36. flags.IntVar(&conf.Mtu, "mtu", 0, "Set the containers network MTU")
  37. flags.BoolVar(&conf.RawLogs, "raw-logs", false, "Full timestamps without ANSI coloring")
  38. flags.Var(opts.NewListOptsRef(&conf.DNS, opts.ValidateIPAddress), "dns", "DNS server to use")
  39. flags.Var(opts.NewNamedListOptsRef("dns-opts", &conf.DNSOptions, nil), "dns-opt", "DNS options to use")
  40. flags.Var(opts.NewListOptsRef(&conf.DNSSearch, opts.ValidateDNSSearch), "dns-search", "DNS search domains to use")
  41. flags.Var(opts.NewNamedListOptsRef("labels", &conf.Labels, opts.ValidateLabel), "label", "Set key=value labels to the daemon")
  42. flags.StringVar(&conf.LogConfig.Type, "log-driver", "json-file", "Default driver for container logs")
  43. flags.Var(opts.NewNamedMapOpts("log-opts", conf.LogConfig.Config, nil), "log-opt", "Default log driver options for containers")
  44. flags.StringVar(&conf.ClusterAdvertise, "cluster-advertise", "", "Address or interface name to advertise")
  45. flags.StringVar(&conf.ClusterStore, "cluster-store", "", "URL of the distributed storage backend")
  46. flags.Var(opts.NewNamedMapOpts("cluster-store-opts", conf.ClusterOpts, nil), "cluster-store-opt", "Set cluster store options")
  47. flags.StringVar(&conf.CorsHeaders, "api-cors-header", "", "Set CORS headers in the Engine API")
  48. flags.IntVar(&maxConcurrentDownloads, "max-concurrent-downloads", config.DefaultMaxConcurrentDownloads, "Set the max concurrent downloads for each pull")
  49. flags.IntVar(&maxConcurrentUploads, "max-concurrent-uploads", config.DefaultMaxConcurrentUploads, "Set the max concurrent uploads for each push")
  50. flags.IntVar(&conf.ShutdownTimeout, "shutdown-timeout", defaultShutdownTimeout, "Set the default shutdown timeout")
  51. flags.IntVar(&conf.NetworkDiagnosticPort, "network-diagnostic-port", 0, "TCP port number of the network diagnostic server")
  52. flags.MarkHidden("network-diagnostic-port")
  53. flags.StringVar(&conf.SwarmDefaultAdvertiseAddr, "swarm-default-advertise-addr", "", "Set default address or interface for swarm advertised address")
  54. flags.BoolVar(&conf.Experimental, "experimental", false, "Enable experimental features")
  55. flags.StringVar(&conf.MetricsAddress, "metrics-addr", "", "Set default address and port to serve the metrics api on")
  56. flags.Var(opts.NewNamedListOptsRef("node-generic-resources", &conf.NodeGenericResources, opts.ValidateSingleGenericResource), "node-generic-resource", "Advertise user-defined resource")
  57. flags.IntVar(&conf.NetworkControlPlaneMTU, "network-control-plane-mtu", config.DefaultNetworkMtu, "Network Control plane MTU")
  58. // "--deprecated-key-path" is to allow configuration of the key used
  59. // for the daemon ID and the deprecated image signing. It was never
  60. // exposed as a command line option but is added here to allow
  61. // overriding the default path in configuration.
  62. flags.Var(opts.NewQuotedString(&conf.TrustKeyPath), "deprecated-key-path", "Path to key file for ID and image signing")
  63. flags.MarkHidden("deprecated-key-path")
  64. conf.MaxConcurrentDownloads = &maxConcurrentDownloads
  65. conf.MaxConcurrentUploads = &maxConcurrentUploads
  66. }
  67. func installRegistryServiceFlags(options *registry.ServiceOptions, flags *pflag.FlagSet) {
  68. ana := opts.NewNamedListOptsRef("allow-nondistributable-artifacts", &options.AllowNondistributableArtifacts, registry.ValidateIndexName)
  69. mirrors := opts.NewNamedListOptsRef("registry-mirrors", &options.Mirrors, registry.ValidateMirror)
  70. insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, registry.ValidateIndexName)
  71. flags.Var(ana, "allow-nondistributable-artifacts", "Allow push of nondistributable artifacts to registry")
  72. flags.Var(mirrors, "registry-mirror", "Preferred Docker registry mirror")
  73. flags.Var(insecureRegistries, "insecure-registry", "Enable insecure registry communication")
  74. if runtime.GOOS != "windows" {
  75. // TODO: Remove this flag after 3 release cycles (18.03)
  76. flags.BoolVar(&options.V2Only, "disable-legacy-registry", true, "Disable contacting legacy registries")
  77. flags.MarkHidden("disable-legacy-registry")
  78. }
  79. }