docker

package
v0.0.0-...-3511abf Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContainerTypeLabel describes container type.
	ContainerTypeLabel = "ai.determined.container.type"
	// ContainerTypeValue is the corresponding value for 'normal tasks'.
	ContainerTypeValue = "task-container"
	// ContainerVersionLabel describes the container version.
	ContainerVersionLabel = "ai.determined.container.version"
	// ContainerVersionValue is the current (and only) container version.
	ContainerVersionValue = "0"
	// ContainerIDLabel gives the Determined container ID (cproto.ID).
	ContainerIDLabel = "ai.determined.container.id"
	// ContainerDevicesLabel describes the devices allocated to the container.
	ContainerDevicesLabel = "ai.determined.container.devices"
	// ContainerDescriptionLabel describes the container.
	ContainerDescriptionLabel = "ai.determined.container.description"
	// AgentLabel gives the agent the container is managed by.
	AgentLabel = "ai.determined.container.agent"
	// ClusterLabel gives the cluster the container is managed by.
	ClusterLabel = "ai.determined.container.cluster"
	// MasterLabel gives the master the container is managed by.
	MasterLabel = "ai.determined.container.master"

	// ImagePullStatsKind describes the IMAGEPULL event.
	ImagePullStatsKind = "IMAGEPULL"
)

Variables

This section is empty.

Functions

func LabelFilter

func LabelFilter(key, val string) filters.Args

LabelFilter is a convenience that takes a key and value and returns a docker label filter.

Types

type Client

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

Client wraps the Docker client, augmenting it with a few higher level convenience APIs.

func NewClient

func NewClient(cl *client.Client) *Client

NewClient populates credentials from the Docker Daemon config and returns a new Client that uses them.

func (*Client) CreateContainer

func (d *Client) CreateContainer(
	ctx context.Context,
	id cproto.ID,
	req cproto.RunSpec,
	p events.Publisher[Event],
) (string, error)

CreateContainer creates a container according to the given spec, returning a docker container ID to start it. It takes a caller-provided channel on which docker events are sent. Slow receivers will block the call.

func (*Client) Inner

func (d *Client) Inner() *client.Client

Inner returns the underlying Docker client, to be used sparingly. TODO(DET-8628): Consolidate around usage of the wrapper client, remove this.

func (*Client) ListRunningContainers

func (d *Client) ListRunningContainers(ctx context.Context, fs filters.Args) (
	map[cproto.ID]types.Container, error,
)

ListRunningContainers lists running Docker containers satisfying the given filters.

func (*Client) PullImage

func (d *Client) PullImage(ctx context.Context, req PullImage, p events.Publisher[Event]) error

PullImage pulls an image according to the given request and credentials initialized at client creation from the Daemon config or credentials helpers configured there. It takes a caller-provided channel on which docker events are sent. Slow receivers will block the call.

func (*Client) ReattachContainer

func (d *Client) ReattachContainer(
	ctx context.Context,
	id cproto.ID,
) (*Container, *aproto.ExitCode, error)

ReattachContainer looks for a single running or terminated container that matches the given filters and returns whether it can be reattached or has terminated.

func (*Client) RemoveContainer

func (d *Client) RemoveContainer(ctx context.Context, id string, force bool) error

RemoveContainer removes a Docker container by ID.

func (*Client) RunContainer

func (d *Client) RunContainer(
	ctx context.Context,
	waitCtx context.Context,
	id string,
	p events.Publisher[Event],
) (*Container, error)

RunContainer runs a container by docker container ID. It takes a caller-provided channel on which docker events are sent. Slow receivers will block the call. RunContainer takes two contexts: one to govern cancellation of running the container, and another to govern the lifetime of the waiter returned. nolint: golint // Both contexts can't both be first.

func (*Client) SignalContainer

func (d *Client) SignalContainer(ctx context.Context, id string, sig syscall.Signal) error

SignalContainer signals the container, by docker container ID, with the requested signal, returning an error if the Docker daemon is unable to process our request.

type Container

type Container struct {
	ContainerInfo   types.ContainerJSON
	ContainerWaiter ContainerWaiter
}

Container contains details about a running container and waiters to await its termination.

type ContainerWaiter

type ContainerWaiter struct {
	Waiter <-chan dcontainer.ContainerWaitOKBody
	Errs   <-chan error
}

ContainerWaiter contains channels to wait on the termination of a running container. Results on the Waiter channel indicate changes in container state, while results on the Errs channel indicate failures to watch for updates.

type Event

type Event struct {
	Log   *LogEvent
	Stats *StatsEvent
}

Event describes some Docker-layer event.

func NewBeginStatsEvent

func NewBeginStatsEvent(kind string) Event

NewBeginStatsEvent initializes a new beginning Event that is of kind 'StatsEvent' for the kind.

func NewEndStatsEvent

func NewEndStatsEvent(kind string) Event

NewEndStatsEvent initializes a new ending Event that is of kind 'StatsEvent' for the kind.

func NewLogEvent

func NewLogEvent(level, message string) Event

NewLogEvent initializes a new Event that is of kind 'LogEvent'. TODO(DET-9076): Logs need agent IDs.

func NewTypedLogEvent

func NewTypedLogEvent(level, message string, stdtype stdcopy.StdType) Event

NewTypedLogEvent initializes a new Event that is of kind 'LogEvent' with a stdtype.

type LogEvent

type LogEvent struct {
	Level     string
	Timestamp time.Time
	Message   string
	Stdtype   stdcopy.StdType
}

LogEvent describes a log emitted from the Docker layer.

type PullImage

type PullImage struct {
	Name      string
	ForcePull bool
	Registry  *types.AuthConfig
}

PullImage describes a request to pull an image.

type StatsEvent

type StatsEvent struct {
	Kind      string
	StartTime *time.Time
	EndTime   *time.Time
}

StatsEvent describes some stats about a Docker operation, such as IMAGEPULL.

Jump to

Keyboard shortcuts

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