client

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildOptions

type BuildOptions struct {
	// Set build-time variables for services.
	BuildArgs map[string]string

	// Compress the build context using gzip.
	Compress bool

	// Always remove intermediate containers.
	ForceRemove bool

	// Set memory limit for the build container.
	Memory string

	// Do not use cache when building the image.
	NoCache bool

	// Do not remove intermediate containers after a successful build.
	NoRemove bool

	// Build images in parallel
	Parallel bool

	// Set type of progress output (`auto`, `plain`, `tty`).
	Progress BuildProgressFlag

	// Always attempt to pull a newer version of the image.
	Pull bool

	// Don't print anything to `STDOUT`.
	Quiet bool

	// Services to build
	Services []string
}

BuildOptions represents the command line options for the `docker compose build` command.

https://docs.docker.com/compose/reference/build/

type BuildProgressFlag

type BuildProgressFlag string
const (
	BuildProgressFlagAuto  BuildProgressFlag = "auto"
	BuildProgressFlagPlain BuildProgressFlag = "plain"
	BuildProgressFlagTTY   BuildProgressFlag = "tty"
)

type Cmd

type Cmd interface {
	SetStderr(stderr io.Writer)
	SetStdout(stdout io.Writer)
	Run(command string) (<-chan error, error)
}

type ComposeClient

type ComposeClient struct {
	GlobalOptions *GlobalOptions
	NewCmd        func() Cmd
}

ComposeClient is used for executing Docker Compose commands. It should be created with `New`.

func New

func New(opts *GlobalOptions) *ComposeClient

New returns a new default ComposeClient

func (*ComposeClient) Build

func (c *ComposeClient) Build(opts *BuildOptions, w io.Writer, overrides ...*GlobalOptions) (<-chan error, error)

docker compose build

Build or rebuild services

stdout is written to the given io.Writer

https://docs.docker.com/compose/reference/build/

func (*ComposeClient) Config

func (c *ComposeClient) Config(opts *ConfigOptions) ([]byte, error)

Returns a byte array representing the Compose file in JSON format.

If Services, Volumes or Hash options are specified, returns a byte array representing the list of services/volumes/hashes (one per line)

https://docs.docker.com/compose/reference/config/

func (*ComposeClient) Down

func (client *ComposeClient) Down(opts *DownOptions, w io.Writer, overrides ...*GlobalOptions) (<-chan error, error)

docker compose down

Stops containers and removes containers, networks, volumes, and images created by `up`.

stderr is written to the given io.Writer

https://docs.docker.com/compose/reference/down/

func (*ComposeClient) RunCommand

func (client *ComposeClient) RunCommand(command, flags string, stdout, stderr io.Writer, overrides ...*GlobalOptions) (<-chan error, error)

RunCommand executes the given docker compose command.

stdout and stderr from the underlying docker compose processes are written to the given io.Writers

Users would normally use of one of the specific command methods (e.g. Up, Down)

func (*ComposeClient) RunQuery

func (client *ComposeClient) RunQuery(command, flags string, overrides ...*GlobalOptions) ([]byte, error)

RunQuery executes the given docker compose query, and returns the stdout stream as a byte array.

Users would normally use of one of the specific query methods (e.g. Version)

func (*ComposeClient) Start added in v1.2.0

func (c *ComposeClient) Start(opts *StartOptions, w io.Writer, overrides ...*GlobalOptions) (<-chan error, error)

docker compose start

Start services

stderr is written to the given io.Writer

https://docs.docker.com/compose/reference/start/

func (*ComposeClient) Stop added in v1.3.0

func (c *ComposeClient) Stop(opts *StopOptions, w io.Writer, overrides ...*GlobalOptions) (<-chan error, error)

docker compose stop

Stop services

stderr is written to the given io.Writer

https://docs.docker.com/compose/reference/stop/

func (*ComposeClient) Up

func (client *ComposeClient) Up(opts *UpOptions, w io.Writer, overrides ...*GlobalOptions) (<-chan error, error)

docker compose up

Builds, (re)creates, starts, and attaches to containers for a service.

stderr is written to the given io.Writer

https://docs.docker.com/compose/reference/up/

func (*ComposeClient) Version

func (c *ComposeClient) Version() (*Version, error)

docker compose version

Show the Docker Compose version information

https://docs.docker.com/engine/reference/commandline/compose_version/

type ConfigOptions added in v1.1.0

type ConfigOptions struct {
	// Pin image tags to digests.
	ResolveImageDigests bool

	// Don't interpolate environment variables.
	NoInterpolate bool

	// Only validate the configuration, don't print anything.
	Quiet bool

	// Print the service names, one per line. Takes precedence over `Volumes` flag.
	// This will make the function return a []byte representing a JSON string array of service names.
	Services bool

	// Print the volume names, one per line. Takes precedence over `Hash` flag.
	// This will make the function return a []byte representing a JSON string array of volume names.
	Volumes bool

	// Print the service config hash, one per line.
	// Set "service1,service2" for a list of specified services or use the wildcard symbol "*" to display all services.
	Hash string
}

type DownOptions

type DownOptions struct {
	// Remove images. Type must be one of:
	//
	// - all: Remove all images used by any service.
	//
	// - local: Remove only images that don't have a custom tag set by the `image` field.
	RemoveImages RemoveImageFlag

	// Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.
	Volumes bool

	// Remove containers for services not defined in the Compose file
	RemoveOrphans bool

	// Specify a shutdown timeout in seconds. (default: 10)
	Timeout *int
}

DownOptions represents the command line options for the `docker compose down` command.

https://docs.docker.com/compose/reference/down/

type GlobalOptions added in v1.1.0

type GlobalOptions struct {
	// Specify alternate compose file(s) (default: docker-compose.yml)
	Files []string

	// Specify an alternate project name (default: directory name)
	ProjectName string

	// Specify a profile to enable
	Profiles []string

	// Show more output
	Verbose *bool

	// Do not print ANSI control characters
	NoANSI *bool

	// Daemon socket to connect to
	Host string

	// Use TLS; implied by TLSVerify
	TLS *bool

	// Trust certs signed only by this CA
	TLSCACert string

	// Path to TLS certificate file
	TLSCert string

	// Path to TLS key file
	TLSKey string

	// Use TLS and verify the remote
	TLSVerify *bool

	// Don't check the daemon's hostname against the name specified in the client certificate
	SkipHostnameCheck bool

	// Specify an alternate working directory (default: the path of the Compose file)
	ProjectDirectory string

	// If set, Compose will attempt to convert deploy keys in v3 files to their non-Swarm equivalent
	Compatibility *bool
}

GlobalOptions represents the global configuration options for the ComposeClient

https://docs.docker.com/compose/reference/

type RemoveImageFlag

type RemoveImageFlag string
const (
	// Remove all images used by any service.
	RemoveImageFlagAll RemoveImageFlag = "all"

	// Remove only images that don't have a custom tag set by the `image` field.
	RemoveImageFlagLocal RemoveImageFlag = "local"
)

type StartOptions added in v1.2.0

type StartOptions struct {
	// Services to start
	Services []string
}

StartOptions represents the command line options for the `docker compose start` command.

https://docs.docker.com/compose/reference/start/

type StopOptions added in v1.3.0

type StopOptions struct {
	// Services to start
	Services []string

	// Specify a shutdown timeout in seconds
	Timeout *int
}

StopOptions represents the command line options for the `docker compose stop` command.

https://docs.docker.com/compose/reference/stop/

type UpOptions

type UpOptions struct {
	// Detached mode: Run containers in the background, print new container names. Detached mode is incompatible with --abort-on-container-exit.
	Detach bool

	// Produce monochrome output.
	NoColor bool

	// Pull without printing progress information.
	QuietPull bool

	// Don't start linked services.
	NoDeps bool

	// Recreate containers even if their configuration and image haven't changed.
	ForceRecreate bool

	// Recreate dependent containers. Incompatible with --no-recreate.
	AlwaysRecreateDeps bool

	// If containers already exist, don't recreate them. Incompatible with --force-recreate and --renew-anon-volumes
	NoRecreate bool

	// Don't build an image, even if it's missing.
	NoBuild bool

	// Don't start the services after creating them.
	NoStart bool

	// Build images before starting containers.
	Build bool

	// Stops all containers if any container was stopped. Incompatible with --detach.
	AbortOnContainerExit bool

	// Attach to dependent containers.
	AttachDependencies bool

	// Use this timeout in seconds for container shutdown when attached or when containers are already running. (default: 10)
	Timeout *int

	// Recreate anonymous volumes instead of retrieving data from the previous containers.
	RenewAnonVolumes bool

	// Remove containers for services not defined in the Compose file.
	RemoveOrphans bool

	// Return the exit code of the selected service container. Implies --abort-on-container-exit.
	ExitCodeFrom string

	// Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.
	Scale map[string]int

	// Defines the services to interact with
	Services []string
}

UpOptions represents the command line options for the `docker compose up` command.

https://docs.docker.com/compose/reference/up/

type Version

type Version struct {
	Version string `json:"version"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL