container

package
v0.5.51 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MPL-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StorageDriverOverlay2     = "overlay2"
	StorageDriverFuse         = "fuse-overlayfs"
	StorageDriverBTRFS        = "btrfs"
	StorageDriverZFS          = "zfs"
	StorageDriverVFS          = "vfs"
	StorageDriverAUFS         = "aufs"
	StorageDriverDeviceMapper = "devicemapper"
	StorageDriverOverlay      = "overlay"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerTasks

type ContainerTasks interface {
	SetForcePull(bool)
	// CreateContainer creates a new container for the given configuration
	// if successful CreateContainer returns the ID of the created container and a nil error
	// if not successful CreateContainer returns a blank string for the id and an error message
	CreateContainer(*types.Container) (id string, err error)
	// Container Info returns an anonymous interface corresponding to the container info
	// returns error when unable to read info such as when the container does not exist.
	ContainerInfo(id string) (interface{}, error)
	// RemoveContainer stops and removes a running container
	RemoveContainer(id string, force bool) error
	// BuildContainer builds a container based on the given configuration
	// If a cached image already exists Build will noop
	// When force is specified BuildContainer will rebuild the container regardless of cached images
	// Returns the canonical name of the built image and an error
	BuildContainer(config *types.Build, force bool) (string, error)
	// CreateVolume creates a new volume with the given name.
	// If successful the id of the newly created volume is returned
	CreateVolume(name string) (id string, err error)
	// RemoveVolume removes a volume with the given name
	RemoveVolume(name string) error
	// FindImageInLocalRegistry returns the unique identifier for an image specified by the given
	// tag in the local registry. If no image is found the function returns an
	// empty id and no error
	// An error is only returned on internal errors when communicating with the
	// Docker API
	FindImageInLocalRegistry(image types.Image) (string, error)
	// FindImageInLocalRegistry returns the unique identifiers for an image specified by the given
	// tag in the local registry. If no image is found the function returns an
	// empty id and no error
	// An error is only returned on internal errors when communicating with the
	// Docker API
	FindImagesInLocalRegistry(filter string) ([]string, error)
	// PullImage pulls a Docker image from the registry if it is not already
	// present in the local cache.
	// If the Username and Password config options are set then PullImage will attempt to
	// authenticate with the registry before pulling the image.
	// If the force parameter is set then PullImage will pull regardless of the image already
	// being cached locally.
	PullImage(image types.Image, force bool) error
	// FindContainerIDs returns the Container IDs for the given container name
	FindContainerIDs(containerName string) ([]string, error)
	// RemoveImage removes the image with the given id from the local registry
	RemoveImage(id string) error
	// ContainerLogs attaches to the container and streams the logs to the returned
	// io.ReadCloser.
	// Returns an error if the container is not running
	ContainerLogs(id string, stdOut, stdErr bool) (io.ReadCloser, error)
	// CopyFromContainer allows the copying of a file from a container
	CopyFromContainer(id, src, dst string) error
	// CopyToContainer allows a file to be copied into a container
	CopyFileToContainer(id, src, dst string) error
	// CreateFileInContainer creates a file with the given contents and name in the container containerID and
	// stores it in the container at the directory path.
	CreateFileInContainer(containerID, contents, filename, path string) error
	// CopyLocaDockerImageToVolume copies the docker images to the docker volume as a
	// compressed archive.
	// the path in the docker volume where the archive is created is returned
	// along with any errors.
	CopyLocalDockerImagesToVolume(images []string, volume string, force bool) ([]string, error)

	//CopyFilesToVolume copies the files to the path in a Docker volume
	CopyFilesToVolume(volume string, files []string, path string, force bool) ([]string, error)
	// Execute command allows the execution of commands in a running docker container
	// id is the id of the container to execute the command in
	// command is a slice of strings to execute
	// timeout in seconds
	// writer [optional] will be used to write any output from the command execution.
	ExecuteCommand(id string, command []string, env []string, workingDirectory string, user, group string, timeout int, writer io.Writer) (int, error)
	// ExecuteScript allows the execution of a script in a running docker container
	// id is the id of the container to execute the command in
	// contents is the contents of the script to execute
	// writer [optional] will be used to write any output from the command execution.
	ExecuteScript(id string, contents string, env []string, workingDirectory string, user, group string, timeout int, writer io.Writer) (int, error)
	// AttachNetwork attaches a container to a network
	// if aliases is set an alias for the container name will be added
	// if ipAddress is not null then a user defined ipaddress will be used
	AttachNetwork(network, containerid string, aliases []string, ipaddress string) error
	// DetatchNetwork disconnects a container from the network
	DetachNetwork(network, containerid string) error
	// ListNetworks lists the networks a container is attached to
	ListNetworks(id string) []types.NetworkAttachment
	// FindNetwork returns a network using the unique resource id
	FindNetwork(id string) (types.NetworkAttachment, error)

	// CreateShell in the running container and attach
	CreateShell(id string, command []string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error

	// Returns basic information related to the Docker Engine
	EngineInfo() *types.EngineInfo
}

ContainerTasks is a task oriented client which abstracts the underlying container technology from the providers this allows different concrete implementations such as Docker, or ContainerD without needing to change the provider code.

The Docker SDK can also be quite terse, the API design for this client is design is centered around performing a task such as CreateContainer, this may be composed of many individual SDK calls.

type Docker

type Docker interface {
	ContainerCreate(
		ctx context.Context,
		config *container.Config,
		hostConfig *container.HostConfig,
		networkingConfig *network.NetworkingConfig,
		platform *specs.Platform,
		containerName string,
	) (container.CreateResponse, error)

	ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
	ContainerStart(context.Context, string, types.ContainerStartOptions) error
	ContainerStop(ctx context.Context, containerID string, options container.StopOptions) error
	ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error
	ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error)
	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
	ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error
	ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
	ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
	ContainerExecResize(ctx context.Context, execID string, config types.ResizeOptions) error
	ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)

	CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error
	CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error)

	CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
	CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)

	NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)
	NetworkInspect(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error)

	NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error)
	NetworkRemove(ctx context.Context, networkID string) error
	NetworkConnect(ctx context.Context, networkID, containerID string, config *network.EndpointSettings) error
	NetworkDisconnect(ctx context.Context, networkID, containerID string, force bool) error

	VolumeList(ctx context.Context, opts volume.ListOptions) (volume.ListResponse, error)
	VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error)
	VolumeRemove(ctx context.Context, volumeID string, force bool) error

	ImagePull(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error)
	ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
	ImageSave(ctx context.Context, imageIDs []string) (io.ReadCloser, error)
	ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
	ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)

	ServerVersion(ctx context.Context) (types.Version, error)
	Info(ctx context.Context) (types.Info, error)
}

Docker defines an interface for a Docker client

func NewDocker

func NewDocker() (Docker, error)

NewDocker creates a new Docker client

type DockerTasks

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

DockerTasks is a concrete implementation of ContainerTasks which uses the Docker SDK

func NewDockerTasks

func NewDockerTasks(c Docker, il images.ImageLog, tg *ctar.TarGz, l logger.Logger) (*DockerTasks, error)

NewDockerTasks creates a DockerTasks with the given Docker client

func (*DockerTasks) AttachNetwork

func (d *DockerTasks) AttachNetwork(net, containerID string, aliases []string, ipAddress string) error

func (*DockerTasks) BuildContainer

func (d *DockerTasks) BuildContainer(config *dtypes.Build, force bool) (string, error)

func (*DockerTasks) ContainerInfo

func (d *DockerTasks) ContainerInfo(id string) (interface{}, error)

ContainerInfo returns the Docker container info

func (*DockerTasks) ContainerLogs

func (d *DockerTasks) ContainerLogs(id string, stdOut, stdErr bool) (io.ReadCloser, error)

ContainerLogs streams the logs for the container to the returned io.ReadCloser

func (*DockerTasks) CopyFileToContainer

func (d *DockerTasks) CopyFileToContainer(containerID, filename, path string) error

CopyFileToContainer copies the file at path filename to the container containerID and stores it in the container at the directory path.

func (*DockerTasks) CopyFilesToVolume

func (d *DockerTasks) CopyFilesToVolume(volumeID string, filenames []string, path string, force bool) ([]string, error)

CopyFileToVolume copies a file to a Docker volume returns the names of the stored files

func (*DockerTasks) CopyFromContainer

func (d *DockerTasks) CopyFromContainer(id, src, dst string) error

CopyFromContainer copies a file from a container

func (*DockerTasks) CopyLocalDockerImagesToVolume

func (d *DockerTasks) CopyLocalDockerImagesToVolume(images []string, volume string, force bool) ([]string, error)

CopyLocalDockerImagesToVolume writes multiple Docker images to a Docker container as a compressed archive returns the filename of the archive and an error if one occurred

func (*DockerTasks) CreateContainer

func (d *DockerTasks) CreateContainer(c *dtypes.Container) (string, error)

CreateContainer creates a new Docker container for the given configuation

func (*DockerTasks) CreateFileInContainer

func (d *DockerTasks) CreateFileInContainer(containerID, contents, filename, path string) error

CreateFileInContainer creates a file with the given contents and name in the container containerID and stores it in the container at the directory path.

func (*DockerTasks) CreateShell

func (d *DockerTasks) CreateShell(id string, command []string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error

CreateShell creates an interactive shell inside a container https://github.com/docker/cli/blob/ae1618713f83e7da07317d579d0675f578de22fa/cli/command/container/exec.go

func (*DockerTasks) CreateVolume

func (d *DockerTasks) CreateVolume(name string) (string, error)

CreateVolume creates a Docker volume for a cluster if the volume exists performs no action returns the volume name and an error if unsuccessful

func (*DockerTasks) DetachNetwork

func (d *DockerTasks) DetachNetwork(network, containerID string) error

DetachNetwork detaches a container from a network TODO: Docker returns success before removing a container tasks which depend on the network being removed may fail in the future we need to check it has been removed before returning

func (*DockerTasks) EngineInfo

func (d *DockerTasks) EngineInfo() *dtypes.EngineInfo

func (*DockerTasks) ExecuteCommand

func (d *DockerTasks) ExecuteCommand(id string, command []string, env []string, workingDir string, user, group string, timeout int, writer io.Writer) (int, error)

ExecuteCommand allows the execution of commands in a running docker container id is the id of the container to execute the command in command is a slice of strings to execute writer [optional] will be used to write any output from the command execution.

func (*DockerTasks) ExecuteScript

func (d *DockerTasks) ExecuteScript(id string, contents string, env []string, workingDir string, user, group string, timeout int, writer io.Writer) (int, error)

ExecuteScript allows the execution of a script in a running docker container id is the id of the container to execute the command in contents is the contents of the script to execute writer [optional] will be used to write any output from the command execution.

func (*DockerTasks) FindContainerIDs

func (d *DockerTasks) FindContainerIDs(fqdn string) ([]string, error)

FindContainerIDs returns the Container IDs for the given identifier

func (*DockerTasks) FindImageInLocalRegistry

func (d *DockerTasks) FindImageInLocalRegistry(image dtypes.Image) (string, error)

FindImageInLocalRegistry returns the id for an image in the local registry that matches the given tag. If no image is found an empty string is returned.

func (*DockerTasks) FindImagesInLocalRegistry

func (d *DockerTasks) FindImagesInLocalRegistry(filter string) ([]string, error)

Finds images in the local registry that match the filter

func (*DockerTasks) FindNetwork

func (d *DockerTasks) FindNetwork(id string) (dtypes.NetworkAttachment, error)

FindNetwork returns a network using the unique resource id

func (*DockerTasks) ListNetworks

func (d *DockerTasks) ListNetworks(id string) []dtypes.NetworkAttachment

ListNetworks lists the networks a container is attached to

func (*DockerTasks) PullImage

func (d *DockerTasks) PullImage(image dtypes.Image, force bool) error

PullImage pulls a Docker image from a remote repo

func (*DockerTasks) RemoveContainer

func (d *DockerTasks) RemoveContainer(id string, force bool) error

RemoveContainer with the given id

func (*DockerTasks) RemoveImage

func (d *DockerTasks) RemoveImage(id string) error

func (*DockerTasks) RemoveVolume

func (d *DockerTasks) RemoveVolume(name string) error

RemoveVolume deletes the Docker volume associated with a cluster

func (*DockerTasks) SetForcePull

func (d *DockerTasks) SetForcePull(force bool)

SetForcePull sets a global override for the DockerTasks, when set to true Images will always be pulled from remote registries

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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