docker

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 12 Imported by: 17

Documentation

Index

Constants

View Source
const (
	Create  = "create"
	Delete  = "delete"
	Destroy = "destroy"
	Die     = "die"
	Export  = "export"
	Kill    = "kill"
	Restart = "restart"
	Start   = "start"
	Stop    = "stop"
	Untag   = "untag"
)

Selectors for the various Docker lifecycle events.

View Source
const AllThingsDocker = "*"

AllThingsDocker is a wildcard used to express interest in the Docker lifecycle event streams of all containers and images.

View Source
const DockerLatest = "latest"
View Source
const (
	Wildcard = "*"
)

Variables

View Source
var (
	ErrAlreadyStarted  = errors.New("docker: container already started")
	ErrRequestTimeout  = errors.New("docker: request timed out")
	ErrKernelShutdown  = errors.New("docker: kernel shutdown")
	ErrNoSuchContainer = errors.New("docker: no such container")
)

Container subsystem error types

Functions

func ImageHistory

func ImageHistory(uuid string) ([]*dockerclient.Image, error)

func ImportImage

func ImportImage(repotag, filename string) error

ImportImage creates a new image in the local repository from a file system archive.

func InspectImage

func InspectImage(uuid string) (*dockerclient.Image, error)

func IsImageNotFound

func IsImageNotFound(err error) bool

IsImageNotFound parses an err to determine whether the image is not found

func LoadImages

func LoadImages(filename string) error

func Logs

func Logs(dockerID string, args []string) error

Logs calls docker logs for a running service container

func PullImage

func PullImage(repotag string) error

func PushImage

func PushImage(repotag string) error

PushImage pushes an image by repotag to local registry, e.g., zenoss/devimg, from the local docker repository

func RunTTL

func RunTTL(cancel <-chan interface{}, min, max time.Duration)

RunTTL starts the ttl to reap stale docker containers.

func SaveImages

func SaveImages(outfile *os.File, repotags ...string) error

func SetDockerClientGetter

func SetDockerClientGetter(getterOverride DockerClientGetter)

Used by tests that need to inject a mock or stub implementation of Client

func StartKernel

func StartKernel()

StartKernel starts up the kernel loop that is responsible for handling all the API calls in a goroutine.

Types

type Client

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

This Client/ClientInterface is a shim for dockerclient.Client. All references to dockerclient.Client shoudl be isolated in Client/ClientInterface

func (*Client) CommitContainer

func (c *Client) CommitContainer(opts dockerclient.CommitContainerOptions) (*dockerclient.Image, error)

func (*Client) CreateContainer

func (*Client) ExportContainer

func (c *Client) ExportContainer(opts dockerclient.ExportContainerOptions) error

func (*Client) ExportImages

func (c *Client) ExportImages(opts dockerclient.ExportImagesOptions) error

func (*Client) ImportImage

func (c *Client) ImportImage(opts dockerclient.ImportImageOptions) error

func (*Client) InspectContainer

func (c *Client) InspectContainer(id string) (*dockerclient.Container, error)

func (*Client) InspectImage

func (c *Client) InspectImage(name string) (*dockerclient.Image, error)

func (*Client) KillContainer

func (c *Client) KillContainer(opts dockerclient.KillContainerOptions) error

func (*Client) ListContainers

func (*Client) ListImages

func (*Client) LoadImage

func (c *Client) LoadImage(opts dockerclient.LoadImageOptions) error

func (*Client) MonitorEvents

func (c *Client) MonitorEvents() (EventMonitor, error)

func (*Client) PullImage

func (*Client) PushImage

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(opts dockerclient.RemoveContainerOptions) error

func (*Client) RemoveImage

func (c *Client) RemoveImage(name string) error

func (*Client) RestartContainer

func (c *Client) RestartContainer(id string, timeout uint) error

func (*Client) StartContainer

func (c *Client) StartContainer(id string, hostConfig *dockerclient.HostConfig) error

func (*Client) StopContainer

func (c *Client) StopContainer(id string, timeout uint) error

func (*Client) TagImage

func (c *Client) TagImage(name string, opts dockerclient.TagImageOptions) error

func (*Client) Version

func (c *Client) Version() (*dockerclient.Env, error)

func (*Client) WaitContainer

func (c *Client) WaitContainer(id string) (int, error)

type ClientInterface

type ClientInterface interface {
	CommitContainer(opts dockerclient.CommitContainerOptions) (*dockerclient.Image, error)

	CreateContainer(opts dockerclient.CreateContainerOptions) (*dockerclient.Container, error)

	ExportContainer(opts dockerclient.ExportContainerOptions) error

	ImportImage(opts dockerclient.ImportImageOptions) error

	ExportImages(opts dockerclient.ExportImagesOptions) error

	LoadImage(opts dockerclient.LoadImageOptions) error

	InspectContainer(id string) (*dockerclient.Container, error)

	InspectImage(name string) (*dockerclient.Image, error)

	KillContainer(opts dockerclient.KillContainerOptions) error

	ListContainers(opts dockerclient.ListContainersOptions) ([]dockerclient.APIContainers, error)

	ListImages(opts dockerclient.ListImagesOptions) ([]dockerclient.APIImages, error)

	MonitorEvents() (EventMonitor, error)

	PullImage(opts dockerclient.PullImageOptions, auth dockerclient.AuthConfiguration) error

	PushImage(opts dockerclient.PushImageOptions, auth dockerclient.AuthConfiguration) error

	RemoveContainer(opts dockerclient.RemoveContainerOptions) error

	RemoveImage(name string) error

	RestartContainer(id string, timeout uint) error

	StartContainer(id string, hostConfig *dockerclient.HostConfig) error

	StopContainer(id string, timeout uint) error

	TagImage(name string, opts dockerclient.TagImageOptions) error

	WaitContainer(id string) (int, error)

	Version() (*dockerclient.Env, error)
}

An interface respresentation of dockerclient.Client

func NewClient

func NewClient() (ClientInterface, error)

type Container

type Container struct {
	*dockerclient.Container
}

Container represents a Docker container.

func Containers

func Containers() ([]*Container, error)

Containers retrieves a list of all the Docker containers.

func FindContainer

func FindContainer(id string) (*Container, error)

FindContainer looks up a container using its id or name.

func NewContainer

func NewContainer(cd *dockerclient.CreateContainerOptions, start bool, timeout time.Duration, oncreate ContainerActionFunc, onstart ContainerActionFunc) (*Container, error)

NewContainer creates a new container and returns its id. The supplied create action, if any, will be executed on successful creation of the container. If a start action is specified it will be executed after the container has been started. Note, if the start parameter is false the container won't be started and the start action will not be executed.

func (*Container) CancelOnEvent

func (c *Container) CancelOnEvent(event string) error

CancelOnEvent cancels the action associated with the specified event.

func (*Container) Commit

func (c *Container) Commit(iidstr string, push bool) (*Image, error)

Commit creates a new Image from the containers changes.

func (*Container) Delete

func (c *Container) Delete(volumes bool) error

Delete removes the container.

func (*Container) Export

func (c *Container) Export(outfile *os.File) error

Export writes the contents of the container's filesystem as a tar archive to outfile.

func (*Container) Inspect

func (c *Container) Inspect() (*dockerclient.Container, error)

Inspect returns information about the container specified by id.

func (*Container) IsRunning

func (c *Container) IsRunning() bool

IsRunning inspects the container and returns true if it is running

func (*Container) Kill

func (c *Container) Kill() error

Kill sends a SIGKILL signal to the container. If the container is not started no action is taken.

func (*Container) OnEvent

func (c *Container) OnEvent(event string, action ContainerActionFunc) error

OnEvent adds an action for the specified event.

func (*Container) Restart

func (c *Container) Restart(timeout time.Duration) error

Restart stops and then restarts a container.

func (*Container) Start

func (c *Container) Start() error

Start uses the information provided in the container definition cd to start a new Docker container. If a container can't be completely started an error is returned. The bool returned specifies whether the caller should expect a events (Start, Die, ...) from the Docker subsystem.

func (*Container) Stop

func (c *Container) Stop(timeout time.Duration) error

Stop stops the container specified by the id. If the container can't be stopped before the timeout expires an error is returned.

func (*Container) Wait

func (c *Container) Wait(timeout time.Duration) (int, error)

Wait blocks until the container stops or the timeout expires and then returns its exit code.

type ContainerActionFunc

type ContainerActionFunc func(id string)

ContainerActionFunc instances are used to handle container action notifications.

type DockerClientGetter

type DockerClientGetter func() (ClientInterface, error)

The function used to get an instance of ClientInterface

type DockerRegistryInterface

type DockerRegistryInterface interface {
	FindImage(repotag string, pull bool) (*Image, error)

	PullImage(repotag string) error

	PushImage(repotag string) error
}

The DockerRegistryInterface is the API for interactions with the docker registry FIXME: Add other methods as time permits. The initial version was only a partial implementation in the interests of time.

type DockerTTL

type DockerTTL struct{}

DockerTTL is the ttl manager for stale docker containers.

func (DockerTTL) Name

func (ttl DockerTTL) Name() string

Name identifies the TTL instance

func (DockerTTL) Purge

func (ttl DockerTTL) Purge(age time.Duration) (time.Duration, error)

Purge cleans up old docker containers and returns the time to live til the next purge. Implements utils.TTL

type EventMonitor

type EventMonitor interface {
	// IsActive reports whether or not an EventMonitor is active, i.e., listening for Docker events.
	IsActive() bool

	// Subscribe returns a subscription to which handlers for the various Docker lifecycle events
	// for the container or image specified by ID (or all containers and images if AllThingsDocker
	// is passed) may be added.
	Subscribe(ID string) (*Subscription, error)

	// Close causes the EventMonitor to stop listening for Docker lifecycle events.
	Close() error
}

EventMonitor implementations may be used to subscribe to Docker lifecycle events. This package provides such an implementation. Instances of it may be retreived via the client.EventMonitor() method.

type HandlerFunc

type HandlerFunc func(e *dockerclient.APIEvents) error

A HandlerFunc is used to receive Docker lifecycle events.

type Image

type Image struct {
	UUID string
	ID   commons.ImageID
}

Image represents a Docker image

func FindImage

func FindImage(repotag string, pull bool) (*Image, error)

FindImage looks up an image by repotag, e.g., zenoss/devimg, from the local repository TODO: add a FindImageByFilter that returns collections of images

func Images

func Images() ([]*Image, error)

Images returns a list of all the named images in the local repository

func TagImage

func TagImage(img *Image, tag string, push bool) (*Image, error)

func (*Image) Delete

func (img *Image) Delete() error

Delete remove the image from the local repository

func (*Image) History

func (img *Image) History() ([]*dockerclient.Image, error)

func (*Image) Inspect

func (img *Image) Inspect() (*dockerclient.Image, error)

func (*Image) Save

func (img *Image) Save(outfile *os.File) error

func (*Image) Tag

func (img *Image) Tag(tag string, push bool) (*Image, error)

Tag tags an image in the local repository

type ImageNotFound

type ImageNotFound struct {
	Tag  string
	Repo string
}

ImageNotFound is a an error type when an image is not found

func (*ImageNotFound) Error

func (err *ImageNotFound) Error() string

Error implements error

type Subscription

type Subscription struct {
	ID string
	// contains filtered or unexported fields
}

Subscription represents a subscription to a particular container or image's Docker lifecycle event stream. The AllThingsDocker ID can be used to subscribe to all container and image event streams.

func (*Subscription) Cancel

func (s *Subscription) Cancel() error

Cancel causes the Subscription to stop receiving and dispatching Docker container and image lifecycle events.

func (*Subscription) Handle

func (s *Subscription) Handle(es string, h HandlerFunc) error

Handle associates a HandlerFunc h with a the Docker container or image lifecycle event specified by es. Any HandlerFunc previously associated with es is replaced.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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