2017-01-23 11:23:07 +00:00
package main
import (
2017-05-16 20:59:38 +00:00
"runtime"
2019-07-11 23:42:16 +00:00
"github.com/docker/docker/daemon"
2017-01-23 11:23:07 +00:00
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/opts"
2019-07-11 23:42:16 +00:00
"github.com/docker/docker/plugin/executor/containerd"
2017-08-29 19:55:09 +00:00
"github.com/docker/docker/registry"
2017-01-23 11:23:07 +00:00
"github.com/spf13/pflag"
)
const (
// defaultShutdownTimeout is the default shutdown timeout for the daemon
defaultShutdownTimeout = 15
2019-06-18 00:23:44 +00:00
// defaultTrustKeyFile is the default filename for the trust key
defaultTrustKeyFile = "key.json"
2017-01-23 11:23:07 +00:00
)
// installCommonConfigFlags adds flags to the pflag.FlagSet to configure the daemon
2018-10-15 07:52:53 +00:00
func installCommonConfigFlags ( conf * config . Config , flags * pflag . FlagSet ) error {
2019-06-25 13:26:36 +00:00
var maxConcurrentDownloads , maxConcurrentUploads , maxDownloadAttempts int
2018-10-15 07:52:53 +00:00
defaultPidFile , err := getDefaultPidFile ( )
if err != nil {
return err
}
defaultDataRoot , err := getDefaultDataRoot ( )
if err != nil {
return err
}
defaultExecRoot , err := getDefaultExecRoot ( )
if err != nil {
return err
}
2017-01-23 11:23:07 +00:00
2017-08-29 19:55:09 +00:00
installRegistryServiceFlags ( & conf . ServiceOptions , flags )
2017-01-23 11:23:07 +00:00
flags . Var ( opts . NewNamedListOptsRef ( "storage-opts" , & conf . GraphOptions , nil ) , "storage-opt" , "Storage driver options" )
flags . Var ( opts . NewNamedListOptsRef ( "authorization-plugins" , & conf . AuthorizationPlugins , nil ) , "authorization-plugin" , "Authorization plugins to load" )
flags . Var ( opts . NewNamedListOptsRef ( "exec-opts" , & conf . ExecOptions , nil ) , "exec-opt" , "Runtime execution options" )
flags . StringVarP ( & conf . Pidfile , "pidfile" , "p" , defaultPidFile , "Path to use for daemon PID file" )
2016-11-22 06:17:24 +00:00
flags . StringVarP ( & conf . Root , "graph" , "g" , defaultDataRoot , "Root of the Docker runtime" )
2017-09-22 13:52:41 +00:00
flags . StringVar ( & conf . ExecRoot , "exec-root" , defaultExecRoot , "Root directory for execution state files" )
flags . StringVar ( & conf . ContainerdAddr , "containerd" , "" , "containerd grpc address" )
2018-06-19 22:53:40 +00:00
flags . BoolVar ( & conf . CriContainerd , "cri-containerd" , false , "start containerd with cri" )
2017-03-28 14:19:35 +00:00
// "--graph" is "soft-deprecated" in favor of "data-root". This flag was added
// before Docker 1.0, so won't be removed, only hidden, to discourage its usage.
2019-08-28 23:51:55 +00:00
_ = flags . MarkHidden ( "graph" )
2017-03-28 14:19:35 +00:00
2016-11-22 06:17:24 +00:00
flags . StringVar ( & conf . Root , "data-root" , defaultDataRoot , "Root directory of persistent Docker state" )
2017-01-23 11:23:07 +00:00
flags . BoolVarP ( & conf . AutoRestart , "restart" , "r" , true , "--restart on the daemon has been deprecated in favor of --restart policies on docker run" )
2019-08-28 23:51:55 +00:00
_ = flags . MarkDeprecated ( "restart" , "Please use a restart policy on docker run" )
2017-05-16 20:59:38 +00:00
// Windows doesn't support setting the storage driver - there is no choice as to which ones to use.
if runtime . GOOS != "windows" {
flags . StringVarP ( & conf . GraphDriver , "storage-driver" , "s" , "" , "Storage driver to use" )
}
2017-01-23 11:23:07 +00:00
flags . IntVar ( & conf . Mtu , "mtu" , 0 , "Set the containers network MTU" )
flags . BoolVar ( & conf . RawLogs , "raw-logs" , false , "Full timestamps without ANSI coloring" )
flags . Var ( opts . NewListOptsRef ( & conf . DNS , opts . ValidateIPAddress ) , "dns" , "DNS server to use" )
flags . Var ( opts . NewNamedListOptsRef ( "dns-opts" , & conf . DNSOptions , nil ) , "dns-opt" , "DNS options to use" )
flags . Var ( opts . NewListOptsRef ( & conf . DNSSearch , opts . ValidateDNSSearch ) , "dns-search" , "DNS search domains to use" )
2019-11-02 00:09:40 +00:00
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" )
2017-01-23 11:23:07 +00:00
flags . Var ( opts . NewNamedListOptsRef ( "labels" , & conf . Labels , opts . ValidateLabel ) , "label" , "Set key=value labels to the daemon" )
flags . StringVar ( & conf . LogConfig . Type , "log-driver" , "json-file" , "Default driver for container logs" )
flags . Var ( opts . NewNamedMapOpts ( "log-opts" , conf . LogConfig . Config , nil ) , "log-opt" , "Default log driver options for containers" )
2020-02-12 17:29:30 +00:00
2017-01-23 11:23:07 +00:00
flags . StringVar ( & conf . ClusterAdvertise , "cluster-advertise" , "" , "Address or interface name to advertise" )
2020-02-19 10:22:20 +00:00
_ = flags . MarkDeprecated ( "cluster-advertise" , "Swarm classic is deprecated. Please use Swarm-mode (docker swarm init)" )
2017-01-23 11:23:07 +00:00
flags . StringVar ( & conf . ClusterStore , "cluster-store" , "" , "URL of the distributed storage backend" )
2020-02-19 10:22:20 +00:00
_ = flags . MarkDeprecated ( "cluster-store" , "Swarm classic is deprecated. Please use Swarm-mode (docker swarm init)" )
2017-01-23 11:23:07 +00:00
flags . Var ( opts . NewNamedMapOpts ( "cluster-store-opts" , conf . ClusterOpts , nil ) , "cluster-store-opt" , "Set cluster store options" )
2020-04-16 12:42:19 +00:00
_ = flags . MarkDeprecated ( "cluster-store-opt" , "Swarm classic is deprecated. Please use Swarm-mode (docker swarm init)" )
2020-02-12 17:29:30 +00:00
2017-01-23 11:23:07 +00:00
flags . StringVar ( & conf . CorsHeaders , "api-cors-header" , "" , "Set CORS headers in the Engine API" )
flags . IntVar ( & maxConcurrentDownloads , "max-concurrent-downloads" , config . DefaultMaxConcurrentDownloads , "Set the max concurrent downloads for each pull" )
flags . IntVar ( & maxConcurrentUploads , "max-concurrent-uploads" , config . DefaultMaxConcurrentUploads , "Set the max concurrent uploads for each push" )
2019-06-25 13:26:36 +00:00
flags . IntVar ( & maxDownloadAttempts , "max-download-attempts" , config . DefaultDownloadAttempts , "Set the max download attempts for each pull" )
2017-01-23 11:23:07 +00:00
flags . IntVar ( & conf . ShutdownTimeout , "shutdown-timeout" , defaultShutdownTimeout , "Set the default shutdown timeout" )
2017-12-01 19:24:14 +00:00
flags . IntVar ( & conf . NetworkDiagnosticPort , "network-diagnostic-port" , 0 , "TCP port number of the network diagnostic server" )
2019-08-28 23:51:55 +00:00
_ = flags . MarkHidden ( "network-diagnostic-port" )
2017-01-23 11:23:07 +00:00
flags . StringVar ( & conf . SwarmDefaultAdvertiseAddr , "swarm-default-advertise-addr" , "" , "Set default address or interface for swarm advertised address" )
flags . BoolVar ( & conf . Experimental , "experimental" , false , "Enable experimental features" )
flags . StringVar ( & conf . MetricsAddress , "metrics-addr" , "" , "Set default address and port to serve the metrics api on" )
2018-01-26 21:15:36 +00:00
flags . Var ( opts . NewNamedListOptsRef ( "node-generic-resources" , & conf . NodeGenericResources , opts . ValidateSingleGenericResource ) , "node-generic-resource" , "Advertise user-defined resource" )
2017-10-29 19:30:31 +00:00
2017-07-28 20:18:49 +00:00
flags . IntVar ( & conf . NetworkControlPlaneMTU , "network-control-plane-mtu" , config . DefaultNetworkMtu , "Network Control plane MTU" )
2017-05-31 00:02:11 +00:00
2017-01-23 11:23:07 +00:00
conf . MaxConcurrentDownloads = & maxConcurrentDownloads
conf . MaxConcurrentUploads = & maxConcurrentUploads
2019-06-25 13:26:36 +00:00
conf . MaxDownloadAttempts = & maxDownloadAttempts
2019-07-11 23:42:16 +00:00
flags . StringVar ( & conf . ContainerdNamespace , "containerd-namespace" , daemon . ContainersNamespace , "Containerd namespace to use" )
flags . StringVar ( & conf . ContainerdPluginNamespace , "containerd-plugins-namespace" , containerd . PluginNamespace , "Containerd namespace to use for plugins" )
2020-11-05 20:14:01 +00:00
return nil
2017-01-23 11:23:07 +00:00
}
2017-08-29 19:55:09 +00:00
func installRegistryServiceFlags ( options * registry . ServiceOptions , flags * pflag . FlagSet ) {
ana := opts . NewNamedListOptsRef ( "allow-nondistributable-artifacts" , & options . AllowNondistributableArtifacts , registry . ValidateIndexName )
mirrors := opts . NewNamedListOptsRef ( "registry-mirrors" , & options . Mirrors , registry . ValidateMirror )
insecureRegistries := opts . NewNamedListOptsRef ( "insecure-registries" , & options . InsecureRegistries , registry . ValidateIndexName )
flags . Var ( ana , "allow-nondistributable-artifacts" , "Allow push of nondistributable artifacts to registry" )
flags . Var ( mirrors , "registry-mirror" , "Preferred Docker registry mirror" )
flags . Var ( insecureRegistries , "insecure-registry" , "Enable insecure registry communication" )
}