github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/cmd/dockerd/config.go (about)

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