command

package
v26.1.5+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2024 License: Apache-2.0 Imports: 64 Imported by: 4,906

Documentation

Index

Constants

View Source
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

View Source
var ErrPromptTerminated = errdefs.Cancelled(errors.New("prompt terminated"))

Functions

func AddPlatformFlag

func AddPlatformFlag(flags *pflag.FlagSet, target *string)

AddPlatformFlag adds `platform` to a set of flags for API version 1.32 and later.

func AddTrustSigningFlags

func AddTrustSigningFlags(fs *pflag.FlagSet, v *bool, trusted bool)

AddTrustSigningFlags adds "signing" flags to the provided flagset

func AddTrustVerificationFlags

func AddTrustVerificationFlags(fs *pflag.FlagSet, v *bool, trusted bool)

AddTrustVerificationFlags adds content trust flags to the provided flagset

func BaseCommandAttributes

func BaseCommandAttributes(cmd *cobra.Command, streams Streams) []attribute.KeyValue

BaseCommandAttributes returns an attribute.Set containing attributes to attach to metrics/traces

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

func CopyToFile(outfile string, r io.Reader) error

CopyToFile writes the content of the reader to the specified file

func DefaultContextStoreConfig

func DefaultContextStoreConfig() store.Config

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

func PrettyPrint(i any) string

PrettyPrint outputs arbitrary data for human formatted output by uppercasing the first letter.

func PromptForConfirmation

func PromptForConfirmation(ctx context.Context, ins io.Reader, outs io.Writer, message string) (bool, error)

PromptForConfirmation requests and checks confirmation from the user. This will display the provided message followed by ' y/N '. If the user input 'y' or 'Y' it returns true otherwise false. If no message is provided, "Are you sure you want to proceed? y/N " will be used instead.

If the user terminates the CLI with SIGINT or SIGTERM while the prompt is active, the prompt will return false with an ErrPromptTerminated error. When the prompt returns an error, the caller should propagate the error up the stack and close the io.Reader used for the prompt which will prevent the background goroutine from blocking indefinitely.

func PruneFilters

func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args

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 ShowHelp

func ShowHelp(err io.Writer) func(*cobra.Command, []string) error

ShowHelp shows the command help.

func StringSliceReplaceAt

func StringSliceReplaceAt(s, find, replace []string, requireIndex int) ([]string, bool)

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

func ValidateOutputPath(path string) error

ValidateOutputPath validates the output paths of the `export` and `save` commands.

func ValidateOutputPathFileMode

func ValidateOutputPathFileMode(fileMode os.FileMode) error

ValidateOutputPathFileMode validates the output paths of the `cp` command and serves as a helper to `ValidateOutputPath`

Types

type CLIOption

type CLIOption func(cli *DockerCli) error

CLIOption is a functional argument to apply options to a DockerCli. These options can be passed to NewDockerCli to initialize a new CLI, or applied with DockerCli.Initialize or DockerCli.Apply.

func WithAPIClient

func WithAPIClient(c client.APIClient) CLIOption

WithAPIClient configures the cli to use the given API client.

func WithBaseContext

func WithBaseContext(ctx context.Context) CLIOption

WithBaseContext sets the base context of a cli. It is used to propagate the context from the command line to the client.

func WithCombinedStreams

func WithCombinedStreams(combined io.Writer) CLIOption

WithCombinedStreams uses the same stream for the output and error streams.

func WithContentTrust

func WithContentTrust(enabled bool) CLIOption

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

func WithErrorStream(err io.Writer) CLIOption

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

func WithOutputStream(out io.Writer) CLIOption

WithOutputStream sets a cli output stream.

func WithResource

func WithResource(res *resource.Resource) CLIOption

WithResource overwrites the default resource and prevents its creation.

func WithResourceOptions

func WithResourceOptions(opts ...resource.Option) CLIOption

WithResourceOptions configures additional options for the default resource. The default resource will continue to include its default options.

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
	TelemetryClient
}

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

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)