github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/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  )
    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 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  
    33  	installRegistryServiceFlags(&conf.ServiceOptions, flags)
    34  
    35  	flags.Var(opts.NewNamedListOptsRef("storage-opts", &conf.GraphOptions, nil), "storage-opt", "Storage driver options")
    36  	flags.Var(opts.NewNamedListOptsRef("authorization-plugins", &conf.AuthorizationPlugins, nil), "authorization-plugin", "Authorization plugins to load")
    37  	flags.Var(opts.NewNamedListOptsRef("exec-opts", &conf.ExecOptions, nil), "exec-opt", "Runtime execution options")
    38  	flags.StringVarP(&conf.Pidfile, "pidfile", "p", defaultPidFile, "Path to use for daemon PID file")
    39  	flags.StringVarP(&conf.Root, "graph", "g", defaultDataRoot, "Root of the Docker runtime")
    40  	flags.StringVar(&conf.ExecRoot, "exec-root", defaultExecRoot, "Root directory for execution state files")
    41  	flags.StringVar(&conf.ContainerdAddr, "containerd", "", "containerd grpc address")
    42  	flags.BoolVar(&conf.CriContainerd, "cri-containerd", false, "start containerd with cri")
    43  
    44  	// "--graph" is "soft-deprecated" in favor of "data-root". This flag was added
    45  	// before Docker 1.0, so won't be removed, only hidden, to discourage its usage.
    46  	flags.MarkHidden("graph")
    47  
    48  	flags.StringVar(&conf.Root, "data-root", defaultDataRoot, "Root directory of persistent Docker state")
    49  
    50  	flags.BoolVarP(&conf.AutoRestart, "restart", "r", true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
    51  	flags.MarkDeprecated("restart", "Please use a restart policy on docker run")
    52  
    53  	// Windows doesn't support setting the storage driver - there is no choice as to which ones to use.
    54  	if runtime.GOOS != "windows" {
    55  		flags.StringVarP(&conf.GraphDriver, "storage-driver", "s", "", "Storage driver to use")
    56  	}
    57  
    58  	flags.IntVar(&conf.Mtu, "mtu", 0, "Set the containers network MTU")
    59  	flags.BoolVar(&conf.RawLogs, "raw-logs", false, "Full timestamps without ANSI coloring")
    60  	flags.Var(opts.NewListOptsRef(&conf.DNS, opts.ValidateIPAddress), "dns", "DNS server to use")
    61  	flags.Var(opts.NewNamedListOptsRef("dns-opts", &conf.DNSOptions, nil), "dns-opt", "DNS options to use")
    62  	flags.Var(opts.NewListOptsRef(&conf.DNSSearch, opts.ValidateDNSSearch), "dns-search", "DNS search domains to use")
    63  	flags.Var(opts.NewNamedListOptsRef("labels", &conf.Labels, opts.ValidateLabel), "label", "Set key=value labels to the daemon")
    64  	flags.StringVar(&conf.LogConfig.Type, "log-driver", "json-file", "Default driver for container logs")
    65  	flags.Var(opts.NewNamedMapOpts("log-opts", conf.LogConfig.Config, nil), "log-opt", "Default log driver options for containers")
    66  	flags.StringVar(&conf.ClusterAdvertise, "cluster-advertise", "", "Address or interface name to advertise")
    67  	flags.StringVar(&conf.ClusterStore, "cluster-store", "", "URL of the distributed storage backend")
    68  	flags.Var(opts.NewNamedMapOpts("cluster-store-opts", conf.ClusterOpts, nil), "cluster-store-opt", "Set cluster store options")
    69  	flags.StringVar(&conf.CorsHeaders, "api-cors-header", "", "Set CORS headers in the Engine API")
    70  	flags.IntVar(&maxConcurrentDownloads, "max-concurrent-downloads", config.DefaultMaxConcurrentDownloads, "Set the max concurrent downloads for each pull")
    71  	flags.IntVar(&maxConcurrentUploads, "max-concurrent-uploads", config.DefaultMaxConcurrentUploads, "Set the max concurrent uploads for each push")
    72  	flags.IntVar(&conf.ShutdownTimeout, "shutdown-timeout", defaultShutdownTimeout, "Set the default shutdown timeout")
    73  	flags.IntVar(&conf.NetworkDiagnosticPort, "network-diagnostic-port", 0, "TCP port number of the network diagnostic server")
    74  	flags.MarkHidden("network-diagnostic-port")
    75  
    76  	flags.StringVar(&conf.SwarmDefaultAdvertiseAddr, "swarm-default-advertise-addr", "", "Set default address or interface for swarm advertised address")
    77  	flags.BoolVar(&conf.Experimental, "experimental", false, "Enable experimental features")
    78  	flags.StringVar(&conf.MetricsAddress, "metrics-addr", "", "Set default address and port to serve the metrics api on")
    79  
    80  	flags.Var(opts.NewNamedListOptsRef("node-generic-resources", &conf.NodeGenericResources, opts.ValidateSingleGenericResource), "node-generic-resource", "Advertise user-defined resource")
    81  
    82  	flags.IntVar(&conf.NetworkControlPlaneMTU, "network-control-plane-mtu", config.DefaultNetworkMtu, "Network Control plane MTU")
    83  
    84  	conf.MaxConcurrentDownloads = &maxConcurrentDownloads
    85  	conf.MaxConcurrentUploads = &maxConcurrentUploads
    86  	return nil
    87  }
    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  
    94  	flags.Var(ana, "allow-nondistributable-artifacts", "Allow push of nondistributable artifacts to registry")
    95  	flags.Var(mirrors, "registry-mirror", "Preferred Docker registry mirror")
    96  	flags.Var(insecureRegistries, "insecure-registry", "Enable insecure registry communication")
    97  }