Documentation ¶
Index ¶
- Constants
- func AddPlatformFlag(flags *pflag.FlagSet, target *string)
- func AddTrustSigningFlags(fs *pflag.FlagSet, v *bool, trusted bool)
- func AddTrustVerificationFlags(fs *pflag.FlagSet, v *bool, trusted bool)
- func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes.AuthConfig, ...) error
- func CopyToFile(outfile string, r io.Reader) error
- func DefaultContextStoreConfig() store.Config
- func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serverAddress string, ...) (registrytypes.AuthConfig, error)
- func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.ConfigFile) (client.APIClient, error)
- func PrettyPrint(i any) string
- func PromptForConfirmation(ins io.Reader, outs io.Writer, message string) bool
- func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args
- func RegisterDefaultStoreEndpoints(ep ...store.NamedTypeGetter)
- func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInfo, cmdName string) types.RequestPrivilegeFunc
- func ResolveAuthConfig(cfg *configfile.ConfigFile, index *registrytypes.IndexInfo) registrytypes.AuthConfig
- func RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (string, error)
- func ShowHelp(err io.Writer) func(*cobra.Command, []string) error
- func StringSliceReplaceAt(s, find, replace []string, requireIndex int) ([]string, bool)
- func UserAgent() string
- func ValidateMountWithAPIVersion(m mounttypes.Mount, serverAPIVersion string) error
- func ValidateOutputPath(path string) error
- func ValidateOutputPathFileMode(fileMode os.FileMode) error
- type CLIOption
- func WithAPIClient(c client.APIClient) CLIOption
- func WithBaseContext(ctx context.Context) CLIOption
- func WithCombinedStreams(combined io.Writer) CLIOption
- func WithContentTrust(enabled bool) CLIOption
- func WithContentTrustFromEnv() CLIOption
- func WithDefaultContextStoreConfig() CLIOption
- func WithErrorStream(err io.Writer) CLIOption
- func WithInitializeClient(makeClient func(dockerCli *DockerCli) (client.APIClient, error)) CLIOption
- func WithInputStream(in io.ReadCloser) CLIOption
- func WithOutputStream(out io.Writer) CLIOption
- func WithStandardStreams() CLIOption
- type Cli
- type ContextStoreWithDefault
- func (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error
- func (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, error)
- func (s *ContextStoreWithDefault) GetStorageInfo(contextName string) store.StorageInfo
- func (s *ContextStoreWithDefault) GetTLSData(contextName, endpointName, fileName string) ([]byte, error)
- func (s *ContextStoreWithDefault) List() ([]store.Metadata, error)
- func (s *ContextStoreWithDefault) ListTLSFiles(name string) (map[string]store.EndpointFiles, error)
- func (s *ContextStoreWithDefault) Remove(name string) error
- func (s *ContextStoreWithDefault) ResetEndpointTLSMaterial(contextName string, endpointName string, data *store.EndpointTLSData) error
- func (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error
- type DefaultContext
- type DefaultContextResolver
- type DockerCli
- func (cli *DockerCli) Apply(ops ...CLIOption) error
- func (cli *DockerCli) BuildKitEnabled() (bool, error)
- func (cli *DockerCli) Client() client.APIClient
- func (cli *DockerCli) ConfigFile() *configfile.ConfigFile
- func (cli *DockerCli) ContentTrustEnabled() bool
- func (cli *DockerCli) ContextStore() store.Store
- func (cli *DockerCli) CurrentContext() string
- func (cli *DockerCli) CurrentVersion() string
- func (cli *DockerCli) DefaultVersion() string
- func (cli *DockerCli) DockerEndpoint() docker.Endpoint
- func (cli *DockerCli) Err() io.Writer
- func (cli *DockerCli) In() *streams.In
- func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption) error
- func (cli *DockerCli) ManifestStore() manifeststore.Store
- func (cli *DockerCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error)
- func (cli *DockerCli) Out() *streams.Out
- func (cli *DockerCli) Protected() Protected
- func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient
- func (cli *DockerCli) ServerInfo() ServerInfo
- func (cli *DockerCli) SetIn(in *streams.In)
- type DockerCliOptiondeprecated
- type DockerContext
- type EndpointDefaultResolver
- type EventHandler
- type InitializeOptdeprecated
- type Protected
- type ServerInfo
- type Streams
Constants ¶
const ( // DefaultContextName is the name reserved for the default context (config & env based) DefaultContextName = "default" // EnvOverrideContext is the name of the environment variable that can be // used to override the context to use. If set, it overrides the context // that's set in the CLI's configuration file, but takes no effect if the // "DOCKER_HOST" env-var is set (which takes precedence. EnvOverrideContext = "DOCKER_CONTEXT" )
Variables ¶
This section is empty.
Functions ¶
func AddPlatformFlag ¶
AddPlatformFlag adds `platform` to a set of flags for API version 1.32 and later.
func AddTrustSigningFlags ¶
AddTrustSigningFlags adds "signing" flags to the provided flagset
func AddTrustVerificationFlags ¶
AddTrustVerificationFlags adds content trust flags to the provided flagset
func ConfigureAuth ¶
func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes.AuthConfig, isDefaultRegistry bool) error
ConfigureAuth handles prompting of user's username and password if needed
func CopyToFile ¶
CopyToFile writes the content of the reader to the specified file
func DefaultContextStoreConfig ¶
DefaultContextStoreConfig returns a new store.Config with the default set of endpoints configured.
func GetDefaultAuthConfig ¶
func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registrytypes.AuthConfig, error)
GetDefaultAuthConfig 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
func NewAPIClientFromFlags ¶
func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.ConfigFile) (client.APIClient, error)
NewAPIClientFromFlags creates a new APIClient from command line flags
func PrettyPrint ¶
PrettyPrint outputs arbitrary data for human formatted output by uppercasing the first letter.
func PromptForConfirmation ¶
PromptForConfirmation requests and checks confirmation from user. This will display the provided message followed by ' y/N '. If the user input 'y' or 'Y' it returns true other false. If no message is provided "Are you sure you want to proceed? y/N " will be used instead.
func PruneFilters ¶
PruneFilters returns consolidated prune filters obtained from config.json and cli
func RegisterDefaultStoreEndpoints ¶
func RegisterDefaultStoreEndpoints(ep ...store.NamedTypeGetter)
RegisterDefaultStoreEndpoints 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.
func RegistryAuthenticationPrivilegedFunc ¶
func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInfo, cmdName string) types.RequestPrivilegeFunc
RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info for the given command.
func ResolveAuthConfig ¶
func ResolveAuthConfig(cfg *configfile.ConfigFile, index *registrytypes.IndexInfo) registrytypes.AuthConfig
ResolveAuthConfig returns auth-config for the given registry from the credential-store. It returns an empty AuthConfig if no credentials were found.
It is similar to [registry.ResolveAuthConfig], but uses the credentials- store, instead of looking up credentials from a map.
func RetrieveAuthTokenFromImage ¶
func RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (string, error)
RetrieveAuthTokenFromImage retrieves an encoded auth token given a complete image. The auth configuration is serialized as a base64url encoded RFC4648, section 5) JSON string for sending through the X-Registry-Auth header.
For details on base64url encoding, see: - RFC4648, section 5: https://tools.ietf.org/html/rfc4648#section-5
func StringSliceReplaceAt ¶
StringSliceReplaceAt replaces the sub-slice find, with the sub-slice replace, in the string slice s, returning a new slice and a boolean indicating if the replacement happened. requireIdx is the index at which old needs to be found at (or -1 to disregard that).
func UserAgent ¶
func UserAgent() string
UserAgent returns the user agent string used for making API requests
func ValidateMountWithAPIVersion ¶
func ValidateMountWithAPIVersion(m mounttypes.Mount, serverAPIVersion string) error
ValidateMountWithAPIVersion validates a mount with the server API version.
func ValidateOutputPath ¶
ValidateOutputPath validates the output paths of the `export` and `save` commands.
func ValidateOutputPathFileMode ¶
ValidateOutputPathFileMode validates the output paths of the `cp` command and serves as a helper to `ValidateOutputPath`
Types ¶
type CLIOption ¶
CLIOption applies a modification on a DockerCli.
func WithAPIClient ¶
WithAPIClient configures the cli to use the given API client.
func WithBaseContext ¶
WithBaseContext sets the base context of a cli. It is used to propagate the context from the command line to the client.
func WithCombinedStreams ¶
WithCombinedStreams uses the same stream for the output and error streams.
func WithContentTrust ¶
WithContentTrust enables content trust on a cli.
func WithContentTrustFromEnv ¶
func WithContentTrustFromEnv() CLIOption
WithContentTrustFromEnv enables content trust on a cli from environment variable DOCKER_CONTENT_TRUST value.
func WithDefaultContextStoreConfig ¶
func WithDefaultContextStoreConfig() CLIOption
WithDefaultContextStoreConfig configures the cli to use the default context store configuration.
func WithErrorStream ¶
WithErrorStream sets a cli error stream.
func WithInitializeClient ¶
func WithInitializeClient(makeClient func(dockerCli *DockerCli) (client.APIClient, error)) CLIOption
WithInitializeClient is passed to DockerCli.Initialize by callers who wish to set a particular API Client for use by the CLI.
func WithInputStream ¶
func WithInputStream(in io.ReadCloser) CLIOption
WithInputStream sets a cli input stream.
func WithOutputStream ¶
WithOutputStream sets a cli output stream.
func WithStandardStreams ¶
func WithStandardStreams() CLIOption
WithStandardStreams sets a cli in, out and err streams with the standard streams.
type Cli ¶
type Cli interface { Client() client.APIClient Streams SetIn(in *streams.In) Apply(ops ...CLIOption) error ConfigFile() *configfile.ConfigFile ServerInfo() ServerInfo NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error) DefaultVersion() string CurrentVersion() string ManifestStore() manifeststore.Store RegistryClient(bool) registryclient.RegistryClient ContentTrustEnabled() bool BuildKitEnabled() (bool, error) ContextStore() store.Store CurrentContext() string DockerEndpoint() docker.Endpoint Protected() Protected }
Cli represents the docker command line client.
type ContextStoreWithDefault ¶
type ContextStoreWithDefault struct { store.Store Resolver DefaultContextResolver }
ContextStoreWithDefault implements the store.Store interface with a support for the default context
func (*ContextStoreWithDefault) CreateOrUpdate ¶
func (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error
CreateOrUpdate is not allowed for the default context and fails
func (*ContextStoreWithDefault) GetMetadata ¶
func (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, error)
GetMetadata implements store.Store's GetMetadata
func (*ContextStoreWithDefault) GetStorageInfo ¶
func (s *ContextStoreWithDefault) GetStorageInfo(contextName string) store.StorageInfo
GetStorageInfo implements store.Store's GetStorageInfo
func (*ContextStoreWithDefault) GetTLSData ¶
func (s *ContextStoreWithDefault) GetTLSData(contextName, endpointName, fileName string) ([]byte, error)
GetTLSData implements store.Store's GetTLSData
func (*ContextStoreWithDefault) List ¶
func (s *ContextStoreWithDefault) List() ([]store.Metadata, error)
List implements store.Store's List
func (*ContextStoreWithDefault) ListTLSFiles ¶
func (s *ContextStoreWithDefault) ListTLSFiles(name string) (map[string]store.EndpointFiles, error)
ListTLSFiles implements store.Store's ListTLSFiles
func (*ContextStoreWithDefault) Remove ¶
func (s *ContextStoreWithDefault) Remove(name string) error
Remove is not allowed for the default context and fails
func (*ContextStoreWithDefault) ResetEndpointTLSMaterial ¶
func (s *ContextStoreWithDefault) ResetEndpointTLSMaterial(contextName string, endpointName string, data *store.EndpointTLSData) error
ResetEndpointTLSMaterial is not implemented for default context and fails
func (*ContextStoreWithDefault) ResetTLSMaterial ¶
func (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error
ResetTLSMaterial is not implemented for default context and fails
type DefaultContext ¶
type DefaultContext struct { Meta store.Metadata TLS store.ContextTLSData }
DefaultContext contains the default context data for all endpoints
func ResolveDefaultContext ¶
func ResolveDefaultContext(opts *cliflags.ClientOptions, config store.Config) (*DefaultContext, error)
ResolveDefaultContext creates a Metadata for the current CLI invocation parameters
type DefaultContextResolver ¶
type DefaultContextResolver func() (*DefaultContext, error)
DefaultContextResolver is a function which resolves the default context base on the configuration and the env variables
type DockerCli ¶
type DockerCli struct {
// contains filtered or unexported fields
}
DockerCli is an instance the docker command line client. Instances of the client can be returned from NewDockerCli.
func NewDockerCli ¶
NewDockerCli returns a DockerCli instance with all operators applied on it. It applies by default the standard streams, and the content trust from environment.
func (*DockerCli) BuildKitEnabled ¶
BuildKitEnabled returns buildkit is enabled or not.
func (*DockerCli) ConfigFile ¶
func (cli *DockerCli) ConfigFile() *configfile.ConfigFile
ConfigFile returns the ConfigFile
func (*DockerCli) ContentTrustEnabled ¶
ContentTrustEnabled returns whether content trust has been enabled by an environment variable.
func (*DockerCli) ContextStore ¶
ContextStore returns the ContextStore
func (*DockerCli) CurrentContext ¶
CurrentContext returns the current context name, based on flags, environment variables and the cli configuration file, in the following order of preference:
- The "--context" command-line option.
- The "DOCKER_CONTEXT" environment variable (EnvOverrideContext).
- The current context as configured through the in "currentContext" field in the CLI configuration file ("~/.docker/config.json").
- If no context is configured, use the "default" context.
Fallbacks for backward-compatibility ¶
To preserve backward-compatibility with the "pre-contexts" behavior, the "default" context is used if:
- The "--host" option is set
- The "DOCKER_HOST" (client.EnvOverrideHost) environment variable is set to a non-empty value.
In these cases, the default context is used, which uses the host as specified in "DOCKER_HOST", and TLS config from flags/env vars.
Setting both the "--context" and "--host" flags is ambiguous and results in an error when the cli is started.
CurrentContext does not validate if the given context exists or if it's valid; errors may occur when trying to use it.
func (*DockerCli) CurrentVersion ¶
CurrentVersion returns the API version currently negotiated, or the default version otherwise.
func (*DockerCli) DefaultVersion ¶
DefaultVersion returns api.defaultVersion.
func (*DockerCli) DockerEndpoint ¶
DockerEndpoint returns the current docker endpoint
func (*DockerCli) Initialize ¶
func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...CLIOption) error
Initialize the dockerCli runs initialization that must happen after command line flags are parsed.
func (*DockerCli) ManifestStore ¶
func (cli *DockerCli) ManifestStore() manifeststore.Store
ManifestStore returns a store for local manifests
func (*DockerCli) NotaryClient ¶
func (cli *DockerCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error)
NotaryClient provides a Notary Repository to interact with signed metadata for an image
func (*DockerCli) RegistryClient ¶
func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient
RegistryClient returns a client for communicating with a Docker distribution registry
func (*DockerCli) ServerInfo ¶
func (cli *DockerCli) ServerInfo() ServerInfo
ServerInfo returns the server version details for the host this client is connected to
type DockerCliOption
deprecated
type DockerContext ¶
DockerContext is a typed representation of what we put in Context metadata
func GetDockerContext ¶
func GetDockerContext(storeMetadata store.Metadata) (DockerContext, error)
GetDockerContext extracts metadata from stored context metadata
func (DockerContext) MarshalJSON ¶
func (dc DockerContext) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshalling
func (*DockerContext) UnmarshalJSON ¶
func (dc *DockerContext) UnmarshalJSON(payload []byte) error
UnmarshalJSON implements custom JSON marshalling
type EndpointDefaultResolver ¶
type EndpointDefaultResolver interface { // ResolveDefault returns values suitable for storing in store.Metadata.Endpoints // and store.ContextTLSData.Endpoints. // // An error is only returned for something fatal, not simply // the lack of a default (e.g. because the config file which // would contain it is missing). If there is no default then // returns nil, nil, nil. // //nolint:dupword // ignore "Duplicate words (nil,) found" ResolveDefault() (any, *store.EndpointTLSData, error) }
EndpointDefaultResolver is implemented by any EndpointMeta object which wants to be able to populate the store with whatever their default is.
type EventHandler ¶
type EventHandler interface { Handle(action events.Action, h func(events.Message)) Watch(c <-chan events.Message) }
EventHandler is abstract interface for user to customize own handle functions of each type of events
func InitEventHandler ¶
func InitEventHandler() EventHandler
InitEventHandler initializes and returns an EventHandler
type InitializeOpt
deprecated
type ServerInfo ¶
type ServerInfo struct { HasExperimental bool OSType string BuildkitVersion types.BuilderVersion // SwarmStatus provides information about the current swarm status of the // engine, obtained from the "Swarm" header in the API response. // // It can be a nil struct if the API version does not provide this header // in the ping response, or if an error occurred, in which case the client // should use other ways to get the current swarm status, such as the /swarm // endpoint. SwarmStatus *swarm.Status }
ServerInfo stores details about the supported features and platform of the server