Help us shape the future of Go! Take the 2026 Go Developer Survey

docker

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package docker is the installer's client of the Docker Engine for what every Docker has: a Client that creates, finds and deletes networks, volumes, containers and images from their specs, one file per kind. What only a swarm has, services, tasks, configs and secrets, is the swarm package's. Around the Client: selecting objects, telling the installer's own, recognising the daemon's errors, and the settings both orchestrators convert alike.

Index

Constants

View Source
const (
	ProvisionCommand = "provision"
)

ProvisionCommand is the command of the installer's image that creates a directory, in the storage mounted at provisionMount: VolumeProvision runs it, and the image answers it with Provision.

Variables

This section is empty.

Functions

func ByInstallation

func ByInstallation(installation installer.Installation) client.Filters

ByInstallation selects the objects of an installation, by their labels.

func ByName

func ByName(name string) client.Filters

ByName selects objects whose name contains name. The daemon matches prefixes, so callers still compare the exact name.

func Content

func Content(object types.FileObjectConfig) []byte

Content returns the content of a config or a secret, or nil for an external one, which is only referenced. installer.LoadProject has read every other one into its Content.

func Environment

func Environment(values types.MappingWithEquals) []string

Environment returns the variables of a service, sorted, the way the daemon takes them: NAME=value, or NAME alone to pass it from the daemon.

func Healthcheck

func Healthcheck(check *types.HealthCheckConfig) *container.HealthConfig

Healthcheck converts the healthcheck of a service.

func IsInUse

func IsInUse(err error) bool

IsInUse reports whether the daemon refused to remove an object because something still uses it: a network with endpoints, a config or a secret a service references, a volume a container mounts. The daemon gives no error kind for it, so the messages are matched.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether the daemon answered that the object does not exist.

func NotOwned

func NotOwned(kind, name string, want map[string]string) error

NotOwned is the error for an object of the project's name that is not the installer's own.

func Owns

func Owns(objectLabels, want map[string]string) bool

Owns reports whether an object the installer found by its name is its own: it carries every label of want. The installer only reuses, updates or removes its own objects; a name taken by anything else is an error.

func Provision

func Provision(directory string) error

Provision is the installer image's side of VolumeProvision: it creates the directory, which must be in the storage mounted at provisionMount.

func SameVolume

func SameVolume(existing, spec *volume.Volume) bool

SameVolume reports whether an existing volume has the driver and options the spec declares. No driver declared means the daemon's default, local.

func Ulimits

func Ulimits(limits map[string]*types.UlimitsConfig) []*container.Ulimit

Ulimits converts the ulimits of a service, sorted by name.

Types

type Client

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

Client drives the Docker Engine of the target. Its methods take the specs the orchestrators convert the compose project into, find objects by their exact name, and name the object in their errors.

func Connect

func Connect(ctx context.Context) (*Client, error)

Connect connects to the Docker Engine of the environment: the socket the runtime mounted, with the io.cnab.docker extension, or DOCKER_HOST and its TLS settings when the installer runs away from the target.

func New

func New(api client.APIClient) *Client

New returns the client of an Engine API connection: the runtime's, which reaches the target the way the docker CLI does.

func (*Client) API

func (docker *Client) API() client.APIClient

API is the Engine API itself, for the clients built on this one.

func (*Client) Close

func (docker *Client) Close() error

func (*Client) ContainerCopy

func (docker *Client) ContainerCopy(ctx context.Context, id string, archive io.Reader) error

ContainerCopy extracts a tar archive at the root of the container, keeping the owners the archive gives.

func (*Client) ContainerCopyFrom

func (docker *Client) ContainerCopyFrom(ctx context.Context, id, path string) (io.ReadCloser, error)

ContainerCopyFrom returns a tar archive of the path in the container.

func (*Client) ContainerCreate

func (docker *Client) ContainerCreate(ctx context.Context, options client.ContainerCreateOptions) (string, error)

func (*Client) ContainerDelete

func (docker *Client) ContainerDelete(ctx context.Context, id string) error

ContainerDelete stops the container and removes it.

func (*Client) ContainerFollow

func (docker *Client) ContainerFollow(ctx context.Context, id string, output io.Writer) (<-chan struct{}, error)

ContainerFollow copies the container's output to output from the start, until it stops. Call it before ContainerStart, so nothing is missed. The channel closes once all of it is copied.

func (*Client) ContainerInspect

func (docker *Client) ContainerInspect(ctx context.Context, id string) (container.InspectResponse, error)

func (*Client) ContainerList

func (docker *Client) ContainerList(ctx context.Context, filters client.Filters) ([]container.Summary, error)

ContainerList lists containers, stopped ones included.

func (*Client) ContainerStart

func (docker *Client) ContainerStart(ctx context.Context, id string) error

func (*Client) ContainerWait

func (docker *Client) ContainerWait(ctx context.Context, id string) (int64, error)

ContainerWait waits until the container stops and returns its exit code.

func (*Client) ImageEnsure

func (docker *Client) ImageEnsure(ctx context.Context, image, policy, registryAuth string) error

ImageEnsure pulls the image, with the encoded credentials of its registry, unless it is on the daemon and the pull policy lets it be used as is.

func (*Client) ImageInspect

func (docker *Client) ImageInspect(ctx context.Context, image string) (image.InspectResponse, error)

ImageInspect describes an image the daemon has.

func (*Client) Info

func (docker *Client) Info(ctx context.Context) (system.Info, error)

Info describes the daemon.

func (*Client) NetworkCreate

func (docker *Client) NetworkCreate(ctx context.Context, spec NetworkSpec) error

func (*Client) NetworkDelete

func (docker *Client) NetworkDelete(ctx context.Context, network *network.Summary) error

func (*Client) NetworkFind

func (docker *Client) NetworkFind(ctx context.Context, name string) (*network.Summary, error)

NetworkFind returns the network of that exact name, or nil.

func (*Client) VolumeCreate

func (docker *Client) VolumeCreate(ctx context.Context, spec *volume.Volume) error

func (*Client) VolumeDelete

func (docker *Client) VolumeDelete(ctx context.Context, volume *volume.Volume) error

VolumeDelete removes the volume, and its data.

func (*Client) VolumeFind

func (docker *Client) VolumeFind(ctx context.Context, name string) (*volume.Volume, error)

VolumeFind returns the volume of that name, or nil.

func (*Client) VolumeProvision

func (docker *Client) VolumeProvision(ctx context.Context, image, registryAuth string, provision target.VolumeProvision) error

VolumeProvision creates the directory of a volume in the storage that provision.Volume mounts: a temporary volume of that storage is mounted in a container of the installer's own image, which creates the directory.

type NetworkSpec

type NetworkSpec struct {
	Name    string
	Options client.NetworkCreateOptions
}

NetworkSpec is a network to create: its name and its options, as both orchestrators convert a compose network.

Jump to

Keyboard shortcuts

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