{"modulePath":"github.com/docker/CLI","version":"v29.10.1+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package command\n\n## Constants\n\n```go\nconst (\n\t// DefaultContextName is the name reserved for the default context (config \u0026 env based)\n\tDefaultContextName = \"default\"\n\n\t// EnvOverrideContext is the name of the environment variable that can be\n\t// used to override the context to use. If set, it overrides the context\n\t// that's set in the CLI's configuration file, but takes no effect if the\n\t// \"DOCKER_HOST\" env-var is set (which takes precedence.\n\tEnvOverrideContext = \"DOCKER_CONTEXT\"\n)\n```\n\n```go\nconst ExportTimeout = 50 * time.Millisecond\n```\n\n## Functions\n\n```go\nfunc BaseCommandAttributes(cmd *cobra.Command, streams Streams) []attribute.KeyValue\n```\nBaseCommandAttributes returns an attribute.Set containing attributes to attach to metrics/traces\n\n```go\nfunc DefaultContextStoreConfig() store.Config\n```\nDefaultContextStoreConfig returns a new store.Config with the default set of endpoints configured.\n\n```go\nfunc GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registrytypes.AuthConfig, error)\n```\nGetDefaultAuthConfig gets the default auth config given a serverAddress If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it\n\n```go\nfunc NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.ConfigFile) (client.APIClient, error)\n```\nNewAPIClientFromFlags creates a new APIClient from command line flags\n\n```go\nfunc PromptUserForCredentials(ctx context.Context, cli Streams, argUser, argPassword, defaultUsername, serverAddress string) (registrytypes.AuthConfig, error)\n```\nPromptUserForCredentials handles the CLI prompt for the user to input credentials. If argUser is not empty, then the user is only prompted for their password. If argPassword is not empty, then the user is only prompted for their username If neither argUser nor argPassword are empty, then the user is not prompted and an AuthConfig is returned with those values. If defaultUsername is not empty, the username prompt includes that username and the user can hit enter without inputting a username  to use that default username.\n\n```go\nfunc PruneFilters(dockerCLI config.Provider, filters client.Filters) client.Filters\n```\nPruneFilters merges prune filters specified in config.json with those specified as command-line flags. It returns a deep copy of filters to prevent mutating the original.\n\nCLI label filters have precedence over those specified in config.json. If a label filter specified as flag conflicts with a label defined in config.json (i.e., \"label=some-value\" conflicts with \"label!=some-value\", and vice versa), then the filter defined in config.json is omitted.\n\n```go\nfunc RegisterDefaultStoreEndpoints(ep ...store.NamedTypeGetter)\n```\nRegisterDefaultStoreEndpoints registers a new named endpoint metadata type with the default context store config, so that endpoint will be supported by stores using the config returned by DefaultContextStoreConfig.\n\n```go\nfunc ResolveAuthConfig(cfg *configfile.ConfigFile, index *registrytypes.IndexInfo) registrytypes.AuthConfig\n```\nResolveAuthConfig returns auth-config for the given registry from the credential-store. It returns an empty AuthConfig if no credentials were found.\n\nDeprecated: this function is no longer used, and will be removed in the next release.\n\n```go\nfunc RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (string, error)\n```\nRetrieveAuthTokenFromImage retrieves an encoded auth token given a complete image reference. The auth configuration is serialized as a base64url encoded ([RFC 4648, Section 5](https://tools.ietf.org/html/rfc4648#section-5)) JSON string for sending through the \"X-Registry-Auth\" header.\n\n```go\nfunc ShowHelp(err io.Writer) func(*cobra.Command, []string) error\n```\nShowHelp shows the command help.\n\n```go\nfunc UserAgent() string\n```\nUserAgent returns the default user agent string used for making API requests.\n\n```go\nfunc ValidateOutputPath(path string) error\n```\nValidateOutputPath validates the output paths of the \"docker cp\" command.\n\n```go\nfunc ValidateOutputPathFileMode(fileMode os.FileMode) error\n```\nValidateOutputPathFileMode validates the output paths of the \"docker cp\" command and serves as a helper to [ValidateOutputPath](#ValidateOutputPath)\n\n## Types\n\n```go\ntype CLIOption func(cli *DockerCli) error\n```\nCLIOption is a functional argument to apply options to a [DockerCli](#DockerCli). These options can be passed to [NewDockerCli](#NewDockerCli) to initialize a new CLI, or applied with [DockerCli.Initialize](#DockerCli.Initialize) or \\[DockerCli.Apply].\n\n```go\nfunc WithAPIClient(c client.APIClient) CLIOption\n```\nWithAPIClient configures the cli to use the given API client.\n\n```go\nfunc WithAPIClientOptions(c ...client.Opt) CLIOption\n```\nWithAPIClientOptions configures additional [client.Opt](/github.com/moby/moby/client#Opt) to use when initializing the API client. These options have no effect if a custom client is set (through [WithAPIClient](#WithAPIClient) or [WithInitializeClient](#WithInitializeClient)).\n\n```go\nfunc WithBaseContext(ctx context.Context) CLIOption\n```\nWithBaseContext sets the base context of a cli. It is used to propagate the context from the command line to the client.\n\n```go\nfunc WithCombinedStreams(combined io.Writer) CLIOption\n```\nWithCombinedStreams uses the same stream for the output and error streams.\n\n```go\nfunc WithContextResolver(resolve func(*DockerCli) (string, error)) CLIOption\n```\nWithContextResolver overrides context selection during [DockerCli.Initialize](#DockerCli.Initialize). The resolver runs after configuration and the context store are loaded, but before telemetry and endpoint initialization. An empty result preserves normal context selection; an error aborts initialization. The resolver must not initialize the API client.\n\n```go\nfunc WithDefaultContextStoreConfig() CLIOption\n```\nWithDefaultContextStoreConfig configures the cli to use the default context store configuration.\n\n```go\nfunc WithEnableGlobalMeterProvider() CLIOption\n```\nWithEnableGlobalMeterProvider configures the DockerCli to create a new MeterProvider from the initialized DockerCli struct, and set it as the global meter provider.\n\nWARNING: For internal use, don't depend on this.\n\n```go\nfunc WithEnableGlobalTracerProvider() CLIOption\n```\nWithEnableGlobalTracerProvider configures the DockerCli to create a new TracerProvider from the initialized DockerCli struct, and set it as the global tracer provider.\n\nWARNING: For internal use, don't depend on this.\n\n```go\nfunc WithErrorStream(err io.Writer) CLIOption\n```\nWithErrorStream sets a cli error stream.\n\n```go\nfunc WithInitializeClient(makeClient func(*DockerCli) (client.APIClient, error)) CLIOption\n```\nWithInitializeClient is passed to [DockerCli.Initialize](#DockerCli.Initialize) to initialize an API Client for use by the CLI.\n\n```go\nfunc WithInputStream(in io.ReadCloser) CLIOption\n```\nWithInputStream sets a cli input stream.\n\n```go\nfunc WithOutputStream(out io.Writer) CLIOption\n```\nWithOutputStream sets a cli output stream.\n\n```go\nfunc WithResource(res *resource.Resource) CLIOption\n```\nWithResource overwrites the default resource and prevents its creation.\n\n```go\nfunc WithResourceOptions(opts ...resource.Option) CLIOption\n```\nWithResourceOptions configures additional options for the default resource. The default resource will continue to include its default options.\n\n```go\nfunc WithStandardStreams() CLIOption\n```\nWithStandardStreams sets a cli in, out and err streams with the standard streams.\n\n```go\nfunc WithUserAgent(userAgent string) CLIOption\n```\nWithUserAgent configures the User-Agent string for cli HTTP requests.\n\n```go\ntype Cli interface {\n\tClient() client.APIClient\n\tStreams\n\tSetIn(in *streams.In)\n\tconfig.Provider\n\tServerInfo() ServerInfo\n\tCurrentVersion() string\n\tBuildKitEnabled() (bool, error)\n\tContextStore() store.Store\n\tCurrentContext() string\n\tDockerEndpoint() docker.Endpoint\n\tTelemetryClient\n}\n```\nCli represents the docker command line client.\n\n```go\ntype ContextStoreWithDefault struct {\n\tstore.Store\n\tResolver DefaultContextResolver\n}\n```\nContextStoreWithDefault implements the store.Store interface with a support for the default context\n\n```go\nfunc (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error\n```\nCreateOrUpdate is not allowed for the default context and fails\n\n```go\nfunc (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, error)\n```\nGetMetadata implements store.Store's GetMetadata\n\n```go\nfunc (s *ContextStoreWithDefault) GetStorageInfo(contextName string) store.StorageInfo\n```\nGetStorageInfo implements store.Store's GetStorageInfo\n\n```go\nfunc (s *ContextStoreWithDefault) GetTLSData(contextName, endpointName, fileName string) ([]byte, error)\n```\nGetTLSData implements store.Store's GetTLSData\n\n```go\nfunc (s *ContextStoreWithDefault) List() ([]store.Metadata, error)\n```\nList implements store.Store's List\n\n```go\nfunc (s *ContextStoreWithDefault) ListTLSFiles(name string) (map[string]store.EndpointFiles, error)\n```\nListTLSFiles implements store.Store's ListTLSFiles\n\n```go\nfunc (s *ContextStoreWithDefault) Remove(name string) error\n```\nRemove is not allowed for the default context and fails\n\n```go\nfunc (s *ContextStoreWithDefault) ResetEndpointTLSMaterial(contextName string, endpointName string, data *store.EndpointTLSData) error\n```\nResetEndpointTLSMaterial is not implemented for default context and fails\n\n```go\nfunc (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error\n```\nResetTLSMaterial is not implemented for default context and fails\n\n```go\ntype DefaultContext struct {\n\tMeta store.Metadata\n\tTLS  store.ContextTLSData\n}\n```\nDefaultContext contains the default context data for all endpoints\n\n```go\ntype DefaultContextResolver func() (*DefaultContext, error)\n```\nDefaultContextResolver is a function which resolves the default context base on the configuration and the env variables\n\n```go\ntype DockerCli struct {\n\t// contains filtered or unexported fields\n}\n```\nDockerCli is an instance the docker command line client. Instances of the client should be created using the [NewDockerCli](#NewDockerCli) constructor to make sure they are properly initialized with defaults set.\n\n```go\nfunc NewDockerCli(ops ...CLIOption) (*DockerCli, error)\n```\nNewDockerCli returns a DockerCli instance with all operators applied on it. It applies by default the standard streams, and the content trust from environment.\n\n```go\nfunc (cli *DockerCli) BuildKitEnabled() (bool, error)\n```\nBuildKitEnabled returns buildkit is enabled or not.\n\n```go\nfunc (cli *DockerCli) Client() client.APIClient\n```\nClient returns the APIClient\n\n```go\nfunc (cli *DockerCli) ConfigFile() *configfile.ConfigFile\n```\nConfigFile returns the ConfigFile\n\n```go\nfunc (cli *DockerCli) ContextStore() store.Store\n```\nContextStore returns the ContextStore\n\n```go\nfunc (cli *DockerCli) CurrentContext() string\n```\nCurrentContext returns the current context name, based on flags, environment variables and the cli configuration file, in the following order of preference:\n\n 1. The \"--context\" command-line option.\n 2. The \"DOCKER\\_CONTEXT\" environment variable ([EnvOverrideContext](#EnvOverrideContext)).\n 3. The current context as configured through the in \"currentContext\" field in the CLI configuration file (\"~/.docker/config.json\").\n 4. If no context is configured, use the \"default\" context.\n\n### Fallbacks for backward-compatibility {#hdr-Fallbacks_for_backward_compatibility}\n\nTo preserve backward-compatibility with the \"pre-contexts\" behavior, the \"default\" context is used if:\n\n  - The \"--host\" option is set\n  - The \"DOCKER\\_HOST\" ([client.EnvOverrideHost](/github.com/moby/moby/client#EnvOverrideHost)) environment variable is set to a non-empty value.\n\nIn these cases, the default context is used, which uses the host as specified in \"DOCKER\\_HOST\", and TLS config from flags/env vars.\n\nSetting both the \"--context\" and \"--host\" flags is ambiguous and results in an error when the cli is started.\n\nCurrentContext does not validate if the given context exists or if it's valid; errors may occur when trying to use it.\n\n```go\nfunc (cli *DockerCli) CurrentVersion() string\n```\nCurrentVersion returns the API version currently negotiated, or the default version otherwise.\n\n```go\nfunc (cli *DockerCli) DockerEndpoint() docker.Endpoint\n```\nDockerEndpoint returns the current docker endpoint\n\n```go\nfunc (cli *DockerCli) Err() *streams.Out\n```\nErr returns the writer used for stderr\n\n```go\nfunc (cli *DockerCli) HooksEnabled() bool\n```\nHooksEnabled returns whether plugin hooks are enabled.\n\n```go\nfunc (cli *DockerCli) In() *streams.In\n```\nIn returns the reader used for stdin\n\n```go\nfunc (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption) error\n```\nInitialize the dockerCli runs initialization that must happen after command line flags are parsed.\n\n```go\nfunc (cli *DockerCli) InstrumentCobraCommands(ctx context.Context, cmd *cobra.Command)\n```\nInstrumentCobraCommands wraps all cobra commands' RunE funcs to set a command duration metric using otel.\n\nNote: this should be the last func to wrap/modify the PersistentRunE/RunE funcs before command execution.\n\ncan also be used for spans!\n\n```go\nfunc (*DockerCli) MeterProvider() metric.MeterProvider\n```\n\n```go\nfunc (cli *DockerCli) Out() *streams.Out\n```\nOut returns the writer used for stdout\n\n```go\nfunc (cli *DockerCli) Resource() *resource.Resource\n```\n\n```go\nfunc (cli *DockerCli) ServerInfo() ServerInfo\n```\nServerInfo returns the server version details for the host this client is connected to\n\n```go\nfunc (cli *DockerCli) SetIn(in *streams.In)\n```\nSetIn sets the reader used for stdin\n\n```go\nfunc (cli *DockerCli) StartInstrumentation(cmd *cobra.Command) (stopInstrumentation func(error))\n```\nStartInstrumentation instruments CLI commands with the individual metrics and spans configured. It's the main command OTel utility, and new command-related metrics should be added to it. It should be called immediately before command execution, and returns a stopInstrumentation function that must be called with the error resulting from the command execution.\n\n```go\nfunc (*DockerCli) TracerProvider() trace.TracerProvider\n```\n\n```go\ntype DockerContext struct {\n\tDescription      string\n\tAdditionalFields map[string]any\n}\n```\nDockerContext is a typed representation of what we put in Context metadata\n\n```go\nfunc GetDockerContext(storeMetadata store.Metadata) (DockerContext, error)\n```\nGetDockerContext extracts metadata from stored context metadata\n\n```go\nfunc (dc DockerContext) MarshalJSON() ([]byte, error)\n```\nMarshalJSON implements custom JSON marshalling\n\n```go\nfunc (dc *DockerContext) UnmarshalJSON(payload []byte) error\n```\nUnmarshalJSON implements custom JSON marshalling\n\n```go\ntype EndpointDefaultResolver interface {\n\t// ResolveDefault returns values suitable for storing in store.Metadata.Endpoints\n\t// and store.ContextTLSData.Endpoints.\n\t//\n\t// An error is only returned for something fatal, not simply\n\t// the lack of a default (e.g. because the config file which\n\t// would contain it is missing). If there is no default then\n\t// returns nil, nil, nil.\n\t//\n\t//nolint:dupword // ignore \"Duplicate words (nil,) found\"\n\tResolveDefault() (any, *store.EndpointTLSData, error)\n}\n```\nEndpointDefaultResolver is implemented by any EndpointMeta object which wants to be able to populate the store with whatever their default is.\n\n```go\ntype MeterProvider interface {\n\tmetric.MeterProvider\n\tForceFlush(ctx context.Context) error\n\tShutdown(ctx context.Context) error\n}\n```\nMeterProvider is an extension of the metric.MeterProvider interface for CLI programs.\n\n```go\ntype ServerInfo struct {\n\tHasExperimental bool\n\tOSType          string\n\tBuildkitVersion build.BuilderVersion\n\n\t// SwarmStatus provides information about the current swarm status of the\n\t// engine, obtained from the \"Swarm\" header in the API response.\n\t//\n\t// It can be a nil struct if the API version does not provide this header\n\t// in the ping response, or if an error occurred, in which case the client\n\t// should use other ways to get the current swarm status, such as the /swarm\n\t// endpoint.\n\tSwarmStatus *client.SwarmStatus\n}\n```\nServerInfo stores details about the supported features and platform of the server\n\n```go\ntype Streams interface {\n\tIn() *streams.In\n\tOut() *streams.Out\n\tErr() *streams.Out\n}\n```\nStreams is an interface which exposes the standard input and output streams\n\n```go\ntype TelemetryClient interface {\n\t// Resource returns the OTEL Resource configured with this TelemetryClient.\n\t// This resource may be created lazily, but the resource should be the same\n\t// each time this function is invoked.\n\tResource() *resource.Resource\n\n\t// TracerProvider returns the currently initialized TracerProvider. This TracerProvider will be configured\n\t// with the default tracing components for a CLI program\n\tTracerProvider() trace.TracerProvider\n\n\t// MeterProvider returns the currently initialized MeterProvider. This MeterProvider will be configured\n\t// with the default metric components for a CLI program\n\tMeterProvider() metric.MeterProvider\n}\n```\nTelemetryClient provides the methods for using OTEL tracing or metrics.\n\n```go\ntype TracerProvider interface {\n\ttrace.TracerProvider\n\tForceFlush(ctx context.Context) error\n\tShutdown(ctx context.Context) error\n}\n```\nTracerProvider is an extension of the trace.TracerProvider interface for CLI programs.\n\n","path":"github.com/docker/CLI/cli/command","name":"command","synopsis":"","isRedistributable":true}
