container

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: AGPL-3.0-or-later Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelPrefix    = "io.netflux.octoplex."
	LabelApp       = LabelPrefix + "app"
	LabelAppID     = LabelPrefix + "app-id"
	LabelComponent = LabelPrefix + "component"
	LabelURL       = LabelPrefix + "url"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides a thin wrapper around the Docker API client, and provides additional functionality such as exposing container stats.

func NewClient

func NewClient(ctx context.Context, params NewParams) (*Client, error)

NewClient creates a new Client.

func (*Client) Close

func (a *Client) Close() error

Close closes the client, stopping and removing all running containers.

func (*Client) ContainerRunning

func (a *Client) ContainerRunning(ctx context.Context, labelOptions LabelOptions) (bool, error)

ContainerRunning checks if a container with the given labels is running.

func (*Client) ContainersWithLabels

func (a *Client) ContainersWithLabels(extraLabels map[string]string) LabelOptions

ContainersWithLabels returns a LabelOptions function that returns the labels for this app instance.

func (*Client) RemoveContainers

func (a *Client) RemoveContainers(ctx context.Context, labelOptions LabelOptions) error

RemoveContainers removes all containers with the given labels.

func (*Client) RemoveUnusedNetworks

func (a *Client) RemoveUnusedNetworks(ctx context.Context) error

RemoveUnusedNetworks removes all networks that are not used by any container.

func (*Client) RunContainer

func (a *Client) RunContainer(ctx context.Context, params RunContainerParams) (<-chan domain.Container, <-chan error)

RunContainer runs a container with the given parameters.

The returned state channel will receive the state of the container and will never be closed. The error channel will receive an error if the container fails to start, and will be closed when the container exits, possibly after receiving an error.

Panics if ShouldRestart is non-nil and the host config defines a restart policy of its own.

type CopyFileConfig

type CopyFileConfig struct {
	Path    string
	Payload io.Reader
	Mode    int64
}

CopyFileConfig holds configuration for a single file which should be copied into a container.

type LabelOptions

type LabelOptions func() map[string]string

LabelOptions is a function that returns a map of labels.

func AllContainers

func AllContainers() LabelOptions

AllContainers returns a LabelOptions function that returns the labels for any app instance.

type LogConfig added in v0.0.6

type LogConfig struct {
	Stdout, Stderr bool
}

LogConfig holds configuration for container logs.

type NetworkCountConfig

type NetworkCountConfig struct {
	Rx string // the network name to count the Rx bytes
	Tx string // the network name to count the Tx bytes
}

NetworkCountConfig holds configuration for observing network traffic.

type NewParams added in v0.0.11

type NewParams struct {
	APIClient DockerClient
	InDocker  bool
	Logger    *slog.Logger
}

NewParams are the parameters for creating a new Client.

type RunContainerParams

type RunContainerParams struct {
	Name               string
	ChanSize           int
	ContainerConfig    *container.Config
	HostConfig         *container.HostConfig
	NetworkingConfig   *network.NetworkingConfig
	NetworkCountConfig NetworkCountConfig
	CopyFiles          []CopyFileConfig
	Logs               LogConfig
	ShouldRestart      ShouldRestartFunc
	RestartInterval    time.Duration // defaults to 10 seconds
}

RunContainerParams are the parameters for running a container.

type ShouldRestartFunc added in v0.0.5

type ShouldRestartFunc func(
	exitCode int64,
	restartCount int,
	containerLogs [][]byte,
	runningTime time.Duration,
) (bool, error)

ShouldRestartFunc is a callback function that is called when a container exits. It should return true if the container is to be restarted. If not restarting, err may be non-nil.

Jump to

Keyboard shortcuts

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