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