docker

package
v0.1.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelManaged   = "gridctl.managed"
	LabelStack     = "gridctl.stack"
	LabelMCPServer = "gridctl.mcp-server"
	LabelResource  = "gridctl.resource"
	LabelAgent     = "gridctl.agent"
)

Labels used to identify gridctl-managed resources.

Variables

This section is empty.

Functions

func AgentLabels

func AgentLabels(stack, name string) map[string]string

AgentLabels returns labels that identify a managed agent container.

func ContainerExists

func ContainerExists(ctx context.Context, cli dockerclient.DockerClient, name string) (bool, string, error)

ContainerExists checks if a container with the given name exists.

func ContainerName

func ContainerName(stack, name string) string

ContainerName generates a deterministic container name.

func CreateContainer

func CreateContainer(ctx context.Context, cli dockerclient.DockerClient, cfg ContainerConfig) (string, error)

CreateContainer creates a new container with the given configuration.

func EnsureImage

func EnsureImage(ctx context.Context, cli dockerclient.DockerClient, imageName string) error

EnsureImage pulls the image if it doesn't exist locally.

func EnsureNetwork

func EnsureNetwork(ctx context.Context, cli dockerclient.DockerClient, name, driver, stack string) (string, error)

EnsureNetwork creates the network if it doesn't exist. The stack parameter is used for labeling (for cleanup).

func GetContainerHostPort

func GetContainerHostPort(ctx context.Context, cli dockerclient.DockerClient, containerID string, containerPort int) (int, error)

GetContainerHostPort returns the host port mapped to a container port.

func GetContainerIP

func GetContainerIP(ctx context.Context, cli dockerclient.DockerClient, containerID, networkName string) (string, error)

GetContainerIP returns the IP address of a container on the specified network.

func ImageExists

func ImageExists(ctx context.Context, cli dockerclient.DockerClient, imageName string) (bool, error)

ImageExists checks if an image exists locally.

func ListManagedContainers

func ListManagedContainers(ctx context.Context, cli dockerclient.DockerClient, stack string) ([]types.Container, error)

ListManagedContainers returns all containers managed by gridctl.

func ListManagedNetworks

func ListManagedNetworks(ctx context.Context, cli dockerclient.DockerClient, stack string) ([]string, error)

ListManagedNetworks returns all networks managed by gridctl for a stack.

func ManagedLabels

func ManagedLabels(stack, name string, isMCPServer bool) map[string]string

ManagedLabels returns labels that identify a managed container.

func NewDockerClient

func NewDockerClient() (dockerclient.DockerClient, error)

NewDockerClient creates a new Docker client using environment defaults.

func Ping

Ping checks if the Docker daemon is accessible.

func RemoveContainer

func RemoveContainer(ctx context.Context, cli dockerclient.DockerClient, containerID string, force bool) error

RemoveContainer removes a container.

func RemoveNetwork

func RemoveNetwork(ctx context.Context, cli dockerclient.DockerClient, name string) error

RemoveNetwork removes a network by name.

func StartContainer

func StartContainer(ctx context.Context, cli dockerclient.DockerClient, containerID string) error

StartContainer starts a container by ID.

func StopContainer

func StopContainer(ctx context.Context, cli dockerclient.DockerClient, containerID string, timeoutSecs int) error

StopContainer stops a container gracefully.

Types

type ContainerConfig

type ContainerConfig struct {
	Name        string
	Image       string
	Command     []string // Override container command
	Env         map[string]string
	Port        int // Container port
	HostPort    int // Host port to publish (0 = auto-assign)
	NetworkName string
	Labels      map[string]string
	Transport   string   // "http" or "stdio"
	Volumes     []string // Volume mounts in "host:container" or "host:container:mode" format
}

ContainerConfig holds the configuration for creating a container.

type DockerRuntime

type DockerRuntime struct {
	// contains filtered or unexported fields
}

DockerRuntime implements runtime.WorkloadRuntime using Docker.

func New

func New() (*DockerRuntime, error)

New creates a new DockerRuntime instance.

func NewWithClient

func NewWithClient(cli dockerclient.DockerClient) *DockerRuntime

NewWithClient creates a DockerRuntime with an existing client (for testing).

func (*DockerRuntime) Client

Client returns the underlying Docker client for advanced use cases. This is needed by MCP gateway for stdio transport and container logs.

func (*DockerRuntime) Close

func (d *DockerRuntime) Close() error

Close releases runtime resources.

func (*DockerRuntime) EnsureImage

func (d *DockerRuntime) EnsureImage(ctx context.Context, imageName string) error

EnsureImage ensures the image is available locally.

func (*DockerRuntime) EnsureNetwork

func (d *DockerRuntime) EnsureNetwork(ctx context.Context, name string, opts runtime.NetworkOptions) error

EnsureNetwork creates the network if it doesn't exist.

func (*DockerRuntime) Exists

func (d *DockerRuntime) Exists(ctx context.Context, name string) (bool, runtime.WorkloadID, error)

Exists checks if a workload exists by name.

func (*DockerRuntime) GetHostPort

func (d *DockerRuntime) GetHostPort(ctx context.Context, id runtime.WorkloadID, exposedPort int) (int, error)

GetHostPort returns the host port for a workload's exposed port.

func (*DockerRuntime) List

List returns all workloads matching the filter.

func (*DockerRuntime) ListNetworks

func (d *DockerRuntime) ListNetworks(ctx context.Context, stack string) ([]string, error)

ListNetworks returns all managed networks for a stack.

func (*DockerRuntime) Ping

func (d *DockerRuntime) Ping(ctx context.Context) error

Ping checks if the runtime is accessible.

func (*DockerRuntime) Remove

func (d *DockerRuntime) Remove(ctx context.Context, id runtime.WorkloadID) error

Remove removes a stopped workload.

func (*DockerRuntime) RemoveNetwork

func (d *DockerRuntime) RemoveNetwork(ctx context.Context, name string) error

RemoveNetwork removes a network by name.

func (*DockerRuntime) Start

Start starts a workload and returns its status.

func (*DockerRuntime) Status

Status returns the current status of a workload.

func (*DockerRuntime) Stop

Stop stops a running workload.

Jump to

Keyboard shortcuts

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