docker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingGPUDriver = errors.New("docker could not find the required gpu driver")

ErrMissingGPUDriver is the expected error if docker is unable to find the required gpu driver.

Functions

This section is empty.

Types

type CommandExecutor

type CommandExecutor struct{}

CommandExecutor is a struct that provides an implementation for executing system commands.

func (*CommandExecutor) Execute

func (e *CommandExecutor) Execute(command string, args ...string) *exec.Cmd

Execute runs the given command with args.

type Docker

type Docker struct {
	RegistryHost string
	// contains filtered or unexported fields
}

Docker is a struct used to interact with the Docker CLI.

func NewDocker

func NewDocker(registryHost string, executor Executor) *Docker

NewDocker creates a new instance of the Docker struct.

registryHost is the host of the Docker registry to interact with. executor is an instance of the Executor interface, which handles command execution.

Returns a pointer to a Docker struct.

func (*Docker) Build

func (d *Docker) Build(dockerfileContent, imageName, platform, buildContext string) error

Build builds a Docker image using buildx and loads the image into the local Docker daemon.

dockerfileContent is the content of the Dockerfile. imageName is the name and tag to apply to the resulting image. This function automatically prefixes it with the value of RegistryHost followed by a forward slash. platform is the target platform for the build (e.g., "linux/amd64"). buildContext is the context of the build.

Returns an error if the build fails.

func (*Docker) Login

func (d *Docker) Login(username string, password string) error

Login logs in to the Docker registry using the provided credentials.

func (*Docker) Logout

func (d *Docker) Logout() error

Logout logs out of the Docker registry.

func (*Docker) Push

func (d *Docker) Push(imageName string) (string, error)

Push pushes a Docker image to the registry.

imageName is the name and tag of the image to push. This function automatically prefixes it with the value of RegistryHost followed by a forward slash.

Returns the image digest on success or an error on failure.

func (*Docker) Run

func (d *Docker) Run(imageName, platform, containerName string, rm, detach bool,
	gpus string, envVars, ports, volumes, command []string) (string, error)

Run runs a Docker container using the provided image name, platform, and additional options.

imageName is the name and tag of the image to run. This function automatically prefixes it with the value of RegistryHost followed by a forward slash. platform is the target platform for the container (e.g., "linux/amd64"). containerName is the name to assign to the running container. rm specifies if the container should be removed after it stops. detach specifies if the container should run in detached mode. gpus specifies the gpus to use. An empty string means that no gpus need to be used. envVars is a list of environment variables to set in the container (e.g., "KEY=value"). ports is a list of port mappings (e.g., "8080:80"). volumes is a list of volume mappings between the host and the container (e.g., "/host/path:/container/path"). command is the command to execute inside the container. If left empty, Docker will use the default command defined by the image.

If the required Nvidia GPU driver is not found, it returns ErrMissingGPUDriver. If there is any other error, it returns that error. Otherwise it returns the output.

type Executor

type Executor interface {
	Execute(command string, args ...string) *exec.Cmd
}

Executor is an interface to abstract command execution.

Jump to

Keyboard shortcuts

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