2017-01-23 11:23:07 +00:00
package main
import (
2023-07-05 11:23:50 +00:00
"runtime"
2017-01-23 11:23:07 +00:00
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/opts"
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"
)
// 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 {
2022-04-23 12:17:51 +00:00
var (
allowNonDistributable = opts . NewNamedListOptsRef ( "allow-nondistributable-artifacts" , & conf . AllowNondistributableArtifacts , registry . ValidateIndexName )
registryMirrors = opts . NewNamedListOptsRef ( "registry-mirrors" , & conf . Mirrors , registry . ValidateMirror )
insecureRegistries = opts . NewNamedListOptsRef ( "insecure-registries" , & conf . InsecureRegistries , registry . ValidateIndexName )
)
flags . Var ( allowNonDistributable , "allow-nondistributable-artifacts" , "Allow push of nondistributable artifacts to registry" )
flags . Var ( registryMirrors , "registry-mirror" , "Preferred Docker registry mirror" )
flags . Var ( insecureRegistries , "insecure-registry" , "Enable insecure registry communication" )
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" )
2022-04-23 12:05:16 +00:00
flags . StringVarP ( & conf . Pidfile , "pidfile" , "p" , conf . Pidfile , "Path to use for daemon PID file" )
flags . StringVar ( & conf . Root , "data-root" , conf . Root , "Root directory of persistent Docker state" )
flags . StringVar ( & conf . ExecRoot , "exec-root" , conf . ExecRoot , "Root directory for execution state files" )
2017-09-22 13:52:41 +00:00
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
2022-01-27 20:13:45 +00:00
flags . Var ( opts . NewNamedMapMapOpts ( "default-network-opts" , conf . DefaultNetworkOpts , nil ) , "default-network-opt" , "Default network options" )
2023-07-05 12:21:04 +00:00
flags . IntVar ( & conf . MTU , "mtu" , conf . MTU , ` Set the MTU for the default "bridge" network ` )
2023-07-05 11:23:50 +00:00
if runtime . GOOS == "windows" {
// The mtu option is not used on Windows, but it has been available since
// "forever" (and always silently ignored). We hide the flag for now,
// to discourage using it (and print a warning if it's set), but not
// "hard-deprecating" it, to not break users, and in case it will be
// supported on Windows in future.
flags . MarkHidden ( "mtu" )
}
2022-06-06 17:38:32 +00:00
flags . IntVar ( & conf . NetworkControlPlaneMTU , "network-control-plane-mtu" , conf . NetworkControlPlaneMTU , "Network Control plane MTU" )
2022-04-23 09:43:31 +00:00
flags . IntVar ( & conf . NetworkDiagnosticPort , "network-diagnostic-port" , 0 , "TCP port number of the network diagnostic server" )
_ = flags . MarkHidden ( "network-diagnostic-port" )
2017-01-23 11:23:07 +00:00
flags . BoolVar ( & conf . RawLogs , "raw-logs" , false , "Full timestamps without ANSI coloring" )
2023-11-13 11:22:04 +00:00
flags . IPSliceVar ( & conf . DNS , "dns" , conf . DNS , "DNS server to use" )
2017-01-23 11:23:07 +00:00
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" )
2022-04-23 21:22:36 +00:00
flags . IPVar ( & conf . HostGatewayIP , "host-gateway-ip" , nil , "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 . CorsHeaders , "api-cors-header" , "" , "Set CORS headers in the Engine API" )
2022-10-26 09:29:08 +00:00
flags . IntVar ( & conf . MaxConcurrentDownloads , "max-concurrent-downloads" , conf . MaxConcurrentDownloads , "Set the max concurrent downloads" )
flags . IntVar ( & conf . MaxConcurrentUploads , "max-concurrent-uploads" , conf . MaxConcurrentUploads , "Set the max concurrent uploads" )
2022-06-06 17:38:32 +00:00
flags . IntVar ( & conf . MaxDownloadAttempts , "max-download-attempts" , conf . MaxDownloadAttempts , "Set the max download attempts for each pull" )
flags . IntVar ( & conf . ShutdownTimeout , "shutdown-timeout" , conf . ShutdownTimeout , "Set the default shutdown timeout" )
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
2022-06-06 17:38:32 +00:00
flags . StringVar ( & conf . ContainerdNamespace , "containerd-namespace" , conf . ContainerdNamespace , "Containerd namespace to use" )
flags . StringVar ( & conf . ContainerdPluginNamespace , "containerd-plugins-namespace" , conf . ContainerdPluginNamespace , "Containerd namespace to use for plugins" )
flags . StringVar ( & conf . DefaultRuntime , "default-runtime" , conf . DefaultRuntime , "Default OCI runtime for containers" )
2021-02-26 23:23:55 +00:00
2021-07-16 07:33:00 +00:00
flags . StringVar ( & conf . HTTPProxy , "http-proxy" , "" , "HTTP proxy URL to use for outgoing traffic" )
flags . StringVar ( & conf . HTTPSProxy , "https-proxy" , "" , "HTTPS proxy URL to use for outgoing traffic" )
flags . StringVar ( & conf . NoProxy , "no-proxy" , "" , "Comma-separated list of hosts or IP addresses for which the proxy is skipped" )
2023-03-09 14:18:40 +00:00
flags . Var ( opts . NewNamedListOptsRef ( "cdi-spec-dirs" , & conf . CDISpecDirs , nil ) , "cdi-spec-dir" , "CDI specification directories to use" )
2022-04-23 09:43:31 +00:00
// Deprecated flags / options
flags . BoolVarP ( & conf . AutoRestart , "restart" , "r" , true , "--restart on the daemon has been deprecated in favor of --restart policies on docker run" )
_ = flags . MarkDeprecated ( "restart" , "Please use a restart policy on docker run" )
2020-11-05 20:14:01 +00:00
return nil
2017-01-23 11:23:07 +00:00
}