dockerutil

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeConfig

func ComposeConfig(ctx context.Context, composeOpt ComposeOptions, configOpt ComposeConfigOptions) error

ComposeConfig parses, resolves, and renders the compose file in canonical format.

ComposeOptions contains general compose config like project name and files. ComposeConfigOptions contains options specific to the config command like format and output.

Returns error if the compose command fails.

func ComposeDown

func ComposeDown(ctx context.Context, composeOpt ComposeOptions, downOpt ComposeDownOptions) error

ComposeDown stops and removes a docker compose project.

ComposeOptions contains general compose config like project name and files. ComposeDownOptions contains options specific to the down command like volumes and timeout.

Returns error if the compose command fails.

func ComposePs

func ComposePs(ctx context.Context, composeOpt ComposeOptions, psOpt ComposePsOptions) error

ComposePs lists containers in a docker compose project.

ComposeOptions contains general compose config like project name and files. ComposePsOptions contains options specific to the ps command.

Returns error if the compose command fails.

func ComposePull

func ComposePull(ctx context.Context, composeOpt ComposeOptions, pullOpt ComposePullOptions) error

ComposePull pulls docker images for a compose project.

ComposeOptions contains general compose config like project name and files. ComposePullOptions contains options specific to the pull command.

Returns error if the compose command fails.

func ComposeUp

func ComposeUp(ctx context.Context, composeOpt ComposeOptions, upOpt ComposeUpOptions) error

ComposeUp starts a docker compose project.

ComposeOptions contains general compose config like project name and files. ComposeUpOptions contains options specific to the up command like detach and timeout.

Returns error if the compose command fails.

func CreateNetworkIfNotExist

func CreateNetworkIfNotExist(ctx context.Context, dockerClient client.APIClient, networkName string) (network.Inspect, error)

CreateNetworkIfNotExist inspects for an existing network and creates it if it does not exist. If the network already exists, it returns the existing network details. This function uses the 'bridge' driver for network creation.

func RemoveNetwork

func RemoveNetwork(ctx context.Context, dockerClient client.APIClient, networkName string) error

func RunInContainer

func RunInContainer(ctx context.Context, logger *slog.Logger, container, command string) error

RunInContainer executes a command in the specified container. The container must be running and the command will be executed in the container's default shell.

func RunInDockerNetwork

func RunInDockerNetwork(ctx context.Context, logger *slog.Logger, image, networkName, command string) error

RunInDockerNetwork executes a command in a temporary container connected to the specified Docker network. The container will be removed after execution.

Types

type ComposeConfigOptions

type ComposeConfigOptions struct {
	DryRun              *bool   //     --dry-run                 Execute command in dry run mode
	Environment         *bool   //     --environment             Print environment used for interpolation.
	Format              *string //     --format string           Format the output. Values: [yaml | json] (default "yaml")
	Hash                *string //     --hash string             Print the service config hash, one per line.
	Images              *bool   //     --images                  Print the image names, one per line.
	NoConsistency       *bool   //     --no-consistency          Don't check model consistency - warning: may produce invalid Compose output
	NoInterpolate       *bool   //     --no-interpolate          Don't interpolate environment variables
	NoNormalize         *bool   //     --no-normalize            Don't normalize compose model
	NoPathResolution    *bool   //     --no-path-resolution      Don't resolve file paths
	Output              *string // -o, --output string           Save to file (default to stdout)
	Profiles            *bool   //     --profiles                Print the profile names, one per line.
	Quiet               *bool   // -q, --quiet                   Only validate the configuration, don't print anything
	ResolveImageDigests *bool   //     --resolve-image-digests   Pin image tags to digests
	Services            *bool   //     --services                Print the service names, one per line.
	Variables           *bool   //     --variables               Print model variables and default values.
	Volumes             *bool   //     --volumes                 Print the volume names, one per line.
}

ComposeConfigOptions represents the options for the config command.

type ComposeDownOptions

type ComposeDownOptions struct {
	DryRun        *bool   //     --dry-run          Execute command in dry run mode
	RemoveOrphans *bool   //     --remove-orphans   Remove containers for services not defined in the Compose file
	Rmi           *string //     --rmi string       Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")
	Timeout       *int    // -t, --timeout int      Specify a shutdown timeout in seconds
	Volumes       *bool   // -v, --volumes          Remove named volumes declared in the "volumes" section
}

ComposeDownOptions represents the options for the down command.

type ComposeOptions

type ComposeOptions struct {
	AllResources     *bool    //     --all-resources              Include all resources, even those not used by services
	Ansi             *string  //     --ansi string                Control when to print ANSI control characters ("never"|"always"|"auto") (default "auto")
	Compatibility    *bool    //     --compatibility              Run compose in backward compatibility mode
	DryRun           *bool    //     --dry-run                    Execute command in dry run mode
	EnvFile          []string //     --env-file stringArray       Specify an alternate environment file
	File             []string // -f, --file stringArray           Compose configuration files
	Parallel         *int     //     --parallel int               Control max parallelism, -1 for unlimited (default -1)
	Profile          []string //     --profile stringArray        Specify a profile to enable
	Progress         *string  //     --progress string            Set type of progress output (auto, tty, plain, json, quiet) (default "auto")
	ProjectDirectory *string  //     --project-directory string   Specify an alternate working directory
	ProjectName      *string  // -p, --project-name string        Project name

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

ComposeOptions represents the options for the compose command.

type ComposePsOptions

type ComposePsOptions struct {
	All      *bool    // -a, --all                 Show all stopped containers (including those created by the run command)
	DryRun   *bool    //     --dry-run             Execute command in dry run mode
	Filter   *string  //     --filter string       Filter services by a property (supported filters: status)
	Format   *string  //     --format string       Format output using a custom template
	NoTrunc  *bool    //     --no-trunc            Don't truncate output
	Orphans  *bool    //     --orphans             Include orphaned services (not declared by project)
	Quiet    *bool    // -q, --quiet               Only display IDs
	Services *bool    //     --services            Display services
	Status   []string //     --status stringArray  Filter services by status

	ServiceNames []string // Optional list of services to show
}

ComposePsOptions represents the options for the ps command.

type ComposePullOptions

type ComposePullOptions struct {
	DryRun             *bool   //     --dry-run                Execute command in dry run mode
	IgnoreBuildable    *bool   //     --ignore-buildable       Ignore images that can be built
	IgnorePullFailures *bool   //     --ignore-pull-failures   Pull what it can and ignores images with pull failures
	IncludeDeps        *bool   //     --include-deps           Also pull services declared as dependencies
	Policy             *string //     --policy string          Apply pull policy ("missing"|"always")
	Quiet              *bool   // -q, --quiet                  Pull without printing progress information

	Services []string // Specific services to pull
}

ComposePullOptions represents the options for the pull command.

type ComposeUpOptions

type ComposeUpOptions struct {
	AbortOnContainerExit    *bool    //     --abort-on-container-exit      Stops all containers if any container was stopped. Incompatible with -d
	AbortOnContainerFailure *bool    //     --abort-on-container-failure   Stops all containers if any container exited with failure. Incompatible with -d
	AlwaysRecreateDeps      *bool    //     --always-recreate-deps         Recreate dependent containers. Incompatible with --no-recreate.
	Attach                  []string //     --attach stringArray           Restrict attaching to the specified services. Incompatible with --attach-dependencies.
	AttachDependencies      *bool    //     --attach-dependencies          Automatically attach to log output of dependent services
	Build                   *bool    //     --build                        Build images before starting containers
	Detach                  *bool    // -d, --detach                       Detached mode: Run containers in the background
	DryRun                  *bool    //     --dry-run                      Execute command in dry run mode
	ExitCodeFrom            *string  //     --exit-code-from string        Return the exit code of the selected service container. Implies --abort-on-container-exit
	ForceRecreate           *bool    //     --force-recreate               Recreate containers even if their configuration and image haven't changed
	Menu                    *bool    //     --menu                         Enable interactive shortcuts when running attached. Incompatible with --detach.
	NoAttach                []string //     --no-attach stringArray        Do not attach (stream logs) to the specified services
	NoBuild                 *bool    //     --no-build                     Don't build an image, even if it's policy
	NoColor                 *bool    //     --no-color                     Produce monochrome output
	NoDeps                  *bool    //     --no-deps                      Don't start linked services
	NoLogPrefix             *bool    //     --no-log-prefix                Don't print prefix in logs
	NoRecreate              *bool    //     --no-recreate                  If containers already exist, don't recreate them. Incompatible with --force-recreate.
	NoStart                 *bool    //     --no-start                     Don't start the services after creating them
	Pull                    *string  //     --pull string                  Pull image before running ("always"|"missing"|"never") (default "policy")
	QuietPull               *bool    //     --quiet-pull                   Pull without printing progress information
	RemoveOrphans           *bool    //     --remove-orphans               Remove containers for services not defined in the Compose file
	RenewAnonVolumes        *bool    // -V, --renew-anon-volumes           Recreate anonymous volumes instead of retrieving data from the previous containers
	Scale                   *string  //     --scale scale                  Scale SERVICE to NUM instances. Overrides the scale setting in the Compose file if present.
	Timeout                 *int     // -t, --timeout int                  Use this timeout in seconds for container shutdown when attached or when containers are already running
	Timestamps              *bool    //     --timestamps                   Show timestamps
	Wait                    *bool    //     --wait                         Wait for services to be running|healthy. Implies detached mode.
	WaitTimeout             *int     //     --wait-timeout int             Maximum duration in seconds to wait for the project to be running|healthy
	Watch                   *bool    // -w, --watch                        Watch source code and rebuild/refresh containers when files are updated.
	Yes                     *bool    // -y, --y                            Assume "yes" as answer to all prompts and run non-interactively
}

ComposeUpOptions represents the options for the up command.

Jump to

Keyboard shortcuts

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