config.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package main
  2. import (
  3. "runtime"
  4. "github.com/docker/docker/daemon"
  5. "github.com/docker/docker/daemon/config"
  6. "github.com/docker/docker/opts"
  7. "github.com/docker/docker/plugin/executor/containerd"
  8. "github.com/docker/docker/registry"
  9. "github.com/spf13/pflag"
  10. )
  11. const (
  12. // defaultShutdownTimeout is the default shutdown timeout for the daemon
  13. defaultShutdownTimeout = 15
  14. // defaultTrustKeyFile is the default filename for the trust key
  15. defaultTrustKeyFile = "key.json"
  16. )
  17. // installCommonConfigFlags adds flags to the pflag.FlagSet to configure the daemon
  18. func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) error {
  19. var maxConcurrentDownloads, maxConcurrentUploads, maxDownloadAttempts int
  20. defaultPidFile, err := getDefaultPidFile()
  21. if err != nil {
  22. return err
  23. }
  24. defaultDataRoot, err := getDefaultDataRoot()
  25. if err != nil {
  26. return err
  27. }
  28. defaultExecRoot, err := getDefaultExecRoot()
  29. if err != nil {
  30. return err
  31. }
  32. installRegistryServiceFlags(&conf.ServiceOptions, flags)
  33. flags.Var(opts.NewNamedListOptsRef("storage-opts", &conf.GraphOptions, nil), "storage-opt", "Storage driver options")
  34. flags.Var(opts.NewNamedListOptsRef("authorization-plugins", &conf.AuthorizationPlugins, nil), "authorization-plugin", "Authorization plugins to load")
  35. flags.Var(opts.NewNamedListOptsRef("exec-opts", &conf.ExecOptions, nil), "exec-opt", "Runtime execution options")
  36. flags.StringVarP(&conf.Pidfile, "pidfile", "p", defaultPidFile, "Path to use for daemon PID file")
  37. flags.StringVarP(&conf.Root, "graph", "g", defaultDataRoot, "Root of the Docker runtime")
  38. flags.StringVar(&conf.ExecRoot, "exec-root", defaultExecRoot, "Root directory for execution state files")
  39. flags.StringVar(&conf.ContainerdAddr, "containerd", "", "containerd grpc address")
  40. flags.BoolVar(&conf.CriContainerd, "cri-containerd", false, "start containerd with cri")
  41. // "--graph" is "soft-deprecated" in favor of "data-root". This flag was added
  42. // before Docker 1.0, so won't be removed, only hidden, to discourage its usage.
  43. _ = flags.MarkHidden("graph")
  44. flags.StringVar(&conf.Root, "data-root", defaultDataRoot, "Root directory of persistent Docker state")
  45. flags.BoolVarP(&conf.AutoRestart, "restart", "r", true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
  46. _ = flags.MarkDeprecated("restart", "Please use a restart policy on docker run")
  47. // Windows doesn't support setting the storage driver - there is no choice as to which ones to use.
  48. if runtime.GOOS != "windows" {
  49. flags.StringVarP(&conf.GraphDriver, "storage-driver", "s", "", "Storage driver to use")
  50. }
  51. flags.IntVar(&conf.Mtu, "mtu", 0, "Set the containers network MTU")
  52. flags.BoolVar(&conf.RawLogs, "raw-logs", false, "Full timestamps without ANSI coloring")
  53. flags.Var(opts.NewListOptsRef(&conf.DNS, opts.ValidateIPAddress), "dns", "DNS server to use")
  54. flags.Var(opts.NewNamedListOptsRef("dns-opts", &conf.DNSOptions, nil), "dns-opt", "DNS options to use")
  55. flags.Var(opts.NewListOptsRef(&conf.DNSSearch, opts.ValidateDNSSearch), "dns-search", "DNS search domains to use")
  56. flags.Var(opts.NewIPOpt(&conf.HostGatewayIP, ""), "host-gateway-ip", "IP address that the special 'host-gateway' string in --add-host resolves to. Defaults to the IP address of the default bridge")
  57. flags.Var(opts.NewNamedListOptsRef("labels", &conf.Labels, opts.ValidateLabel), "label", "Set key=value labels to the daemon")
  58. flags.StringVar(&conf.LogConfig.Type, "log-driver", "json-file", "Default driver for container logs")
  59. flags.Var(opts.NewNamedMapOpts("log-opts", conf.LogConfig.Config, nil), "log-opt", "Default log driver options for containers")
  60. flags.StringVar(&conf.ClusterAdvertise, "cluster-advertise", "", "Address or interface name to advertise")
  61. _ = flags.MarkDeprecated("cluster-advertise", "Swarm classic is deprecated. Please use Swarm-mode (docker swarm init)")
  62. flags.StringVar(&conf.ClusterStore, "cluster-store", "", "URL of the distributed storage backend")
  63. _ = flags.MarkDeprecated("cluster-store", "Swarm classic is deprecated. Please use Swarm-mode (docker swarm init)")
  64. flags.Var(opts.NewNamedMapOpts("cluster-store-opts", conf.ClusterOpts, nil), "cluster-store-opt", "Set cluster store options")
  65. _ = flags.MarkDeprecated("cluster-store-opt", "Swarm classic is deprecated. Please use Swarm-mode (docker swarm init)")
  66. flags.StringVar(&conf.CorsHeaders, "api-cors-header", "", "Set CORS headers in the Engine API")
  67. flags.IntVar(&maxConcurrentDownloads, "max-concurrent-downloads", config.DefaultMaxConcurrentDownloads, "Set the max concurrent downloads for each pull")
  68. flags.IntVar(&maxConcurrentUploads, "max-concurrent-uploads", config.DefaultMaxConcurrentUploads, "Set the max concurrent uploads for each push")
  69. flags.IntVar(&maxDownloadAttempts, "max-download-attempts", config.DefaultDownloadAttempts, "Set the max download attempts for each pull")
  70. flags.IntVar(&conf.ShutdownTimeout, "shutdown-timeout", defaultShutdownTimeout, "Set the default shutdown timeout")
  71. flags.IntVar(&conf.NetworkDiagnosticPort, "network-diagnostic-port", 0, "TCP port number of the network diagnostic server")
  72. _ = flags.MarkHidden("network-diagnostic-port")
  73. flags.StringVar(&conf.SwarmDefaultAdvertiseAddr, "swarm-default-advertise-addr", "", "Set default address or interface for swarm advertised address")
  74. flags.BoolVar(&conf.Experimental, "experimental", false, "Enable experimental features")
  75. flags.StringVar(&conf.MetricsAddress, "metrics-addr", "", "Set default address and port to serve the metrics api on")
  76. flags.Var(opts.NewNamedListOptsRef("node-generic-resources", &conf.NodeGenericResources, opts.ValidateSingleGenericResource), "node-generic-resource", "Advertise user-defined resource")
  77. flags.IntVar(&conf.NetworkControlPlaneMTU, "network-control-plane-mtu", config.DefaultNetworkMtu, "Network Control plane MTU")
  78. conf.MaxConcurrentDownloads = &maxConcurrentDownloads
  79. conf.MaxConcurrentUploads = &maxConcurrentUploads
  80. conf.MaxDownloadAttempts = &maxDownloadAttempts
  81. flags.StringVar(&conf.ContainerdNamespace, "containerd-namespace", daemon.ContainersNamespace, "Containerd namespace to use")
  82. flags.StringVar(&conf.ContainerdPluginNamespace, "containerd-plugins-namespace", containerd.PluginNamespace, "Containerd namespace to use for plugins")
  83. flags.StringVar(&conf.DefaultRuntime, "default-runtime", config.StockRuntimeName, "Default OCI runtime for containers")
  84. flags.StringVar(&conf.HTTPProxy, "http-proxy", "", "HTTP proxy URL to use for outgoing traffic")
  85. flags.StringVar(&conf.HTTPSProxy, "https-proxy", "", "HTTPS proxy URL to use for outgoing traffic")
  86. flags.StringVar(&conf.NoProxy, "no-proxy", "", "Comma-separated list of hosts or IP addresses for which the proxy is skipped")
  87. return nil
  88. }
  89. func installRegistryServiceFlags(options *registry.ServiceOptions, flags *pflag.FlagSet) {
  90. ana := opts.NewNamedListOptsRef("allow-nondistributable-artifacts", &options.AllowNondistributableArtifacts, registry.ValidateIndexName)
  91. mirrors := opts.NewNamedListOptsRef("registry-mirrors", &options.Mirrors, registry.ValidateMirror)
  92. insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, registry.ValidateIndexName)
  93. flags.Var(ana, "allow-nondistributable-artifacts", "Allow push of nondistributable artifacts to registry")
  94. flags.Var(mirrors, "registry-mirror", "Preferred Docker registry mirror")
  95. flags.Var(insecureRegistries, "insecure-registry", "Enable insecure registry communication")
  96. }