docker

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSuchContainer = errors.New("container does not exist")

ErrNoSuchContainer is the error returned when an operation is requested on a non-existent container.

Functions

func NewMock

func NewMock() (*MockClient, Client)

NewMock creates a mock docker client suitable for use in unit tests, and a MockClient that allows testers to manipulate it's behavior.

Types

type BuildImageOptions

type BuildImageOptions struct {
	Name, Dockerfile string
}

BuildImageOptions represents the parameters in a call to BuildImage.

type Client

type Client struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

A Client to the local docker daemon.

func New

func New(sock string) Client

New creates client to the docker daemon.

func (Client) Build

func (dk Client) Build(name, dockerfile string) (id string, err error)

Build builds an image with the given name and Dockerfile, and returns the ID of the resulting image.

func (Client) ConfigureNetwork

func (dk Client) ConfigureNetwork(driver string) error

ConfigureNetwork makes a request to docker to create a network running on driver.

func (Client) Get

func (dk Client) Get(id string) (Container, error)

Get returns a Container corresponding to the supplied ID.

func (Client) IsRunning

func (dk Client) IsRunning(name string) (bool, error)

IsRunning returns true if the container with the given `name` is running.

func (Client) List

func (dk Client) List(filters map[string][]string) ([]Container, error)

List returns a slice of all running containers. The List can be be filtered with the supplied `filters` map.

func (Client) Pull

func (dk Client) Pull(image string) error

Pull retrieves the given docker image from an image cache. The `image` argument can be of the form <repo>, <repo>:<tag>, or <repo>:<tag>@<digestFormat>:<digest>. If no tag is specified, then the "latest" tag is applied.

func (Client) Push

func (dk Client) Push(registry, image string) error

Push pushes the given image to the registry.

func (Client) Remove

func (dk Client) Remove(name string) error

Remove stops and deletes the container with the given name.

func (Client) RemoveID

func (dk Client) RemoveID(id string) error

RemoveID stops and deletes the container with the given ID.

func (Client) Run

func (dk Client) Run(opts RunOptions) (string, error)

Run creates and starts a new container in accordance RunOptions.

type Container

type Container struct {
	ID      string
	EID     string
	Name    string
	Image   string
	ImageID string
	IP      string
	Mac     string
	Path    string
	Status  string
	Args    []string
	Pid     int
	Env     map[string]string
	Labels  map[string]string
	Created time.Time
}

A Container as returned by the docker client API.

type ContainerSlice

type ContainerSlice []Container

ContainerSlice is an alias for []Container to allow for joins

func (ContainerSlice) Get

func (cs ContainerSlice) Get(ii int) interface{}

Get returns the value contained at the given index

func (ContainerSlice) Len

func (cs ContainerSlice) Len() int

Len returns the number of items in the slice

type MockClient

type MockClient struct {
	*sync.Mutex
	Built      map[BuildImageOptions]struct{}
	Pulled     map[string]struct{}
	Pushed     map[dkc.PushImageOptions]struct{}
	Containers map[string]mockContainer
	Networks   map[string]*dkc.Network
	Uploads    map[UploadToContainerOptions]struct{}
	Images     map[string]*dkc.Image

	Executions map[string][]string

	CreateError           bool
	CreateNetworkError    bool
	ListNetworksError     bool
	CreateExecError       bool
	InspectContainerError bool
	InspectImageError     bool
	ListError             bool
	BuildError            bool
	PullError             bool
	PushError             bool
	RemoveError           bool
	StartError            bool
	StartExecError        bool
	UploadError           bool
	// contains filtered or unexported fields
}

MockClient gives unit testers access to the internals of the mock docker client returned by NewMock.

func (MockClient) BuildImage

func (dk MockClient) BuildImage(opts dkc.BuildImageOptions) error

BuildImage builds the requested image.

func (*MockClient) CreateContainer

func (dk *MockClient) CreateContainer(opts dkc.CreateContainerOptions) (*dkc.Container,
	error)

CreateContainer creates a container in accordance with the supplied options.

func (MockClient) CreateExec

func (dk MockClient) CreateExec(opts dkc.CreateExecOptions) (*dkc.Exec, error)

CreateExec creates an execution option to be started by StartExec.

func (MockClient) CreateNetwork

func (dk MockClient) CreateNetwork(opts dkc.CreateNetworkOptions) (*dkc.Network, error)

CreateNetwork creates a network according to opts.

func (MockClient) DownloadFromContainer

func (dk MockClient) DownloadFromContainer(id string,
	opts dkc.DownloadFromContainerOptions) error

DownloadFromContainer is not implemented.

func (MockClient) InspectContainer

func (dk MockClient) InspectContainer(id string) (*dkc.Container, error)

InspectContainer returns details of the specified container.

func (MockClient) InspectImage

func (dk MockClient) InspectImage(name string) (*dkc.Image, error)

InspectImage inspects the requested image.

func (MockClient) ListContainers

func (dk MockClient) ListContainers(opts dkc.ListContainersOptions) ([]dkc.APIContainers,
	error)

ListContainers lists the running containers.

func (MockClient) ListNetworks

func (dk MockClient) ListNetworks() ([]dkc.Network, error)

ListNetworks lists all networks.

func (MockClient) PullImage

func (dk MockClient) PullImage(opts dkc.PullImageOptions,
	auth dkc.AuthConfiguration) error

PullImage pulls the requested image.

func (MockClient) PushImage

func (dk MockClient) PushImage(opts dkc.PushImageOptions, _ dkc.AuthConfiguration) error

PushImage pushes the requested image.

func (MockClient) RemoveContainer

func (dk MockClient) RemoveContainer(opts dkc.RemoveContainerOptions) error

RemoveContainer removes the given docker container.

func (*MockClient) ResetBuilt

func (dk *MockClient) ResetBuilt()

ResetBuilt clears the list of built images, for use by the unit tests.

func (*MockClient) ResetExec

func (dk *MockClient) ResetExec()

ResetExec clears the list of created and started executions, for use by the unit tests.

func (MockClient) StartContainer

func (dk MockClient) StartContainer(id string, hostConfig *dkc.HostConfig) error

StartContainer starts the given docker container.

func (MockClient) StartExec

func (dk MockClient) StartExec(id string, opts dkc.StartExecOptions) error

StartExec starts the supplied execution object.

func (MockClient) StopContainer

func (dk MockClient) StopContainer(id string)

StopContainer stops the given docker container.

func (MockClient) UploadToContainer

func (dk MockClient) UploadToContainer(id string,
	opts dkc.UploadToContainerOptions) error

UploadToContainer extracts a tarball into the given container.

type RunOptions

type RunOptions struct {
	Name              string
	Image             string
	Args              []string
	Labels            map[string]string
	Env               map[string]string
	FilepathToContent map[string]string

	IP          string
	NetworkMode string
	DNS         []string
	DNSSearch   []string

	PidMode     string
	Privileged  bool
	VolumesFrom []string
}

RunOptions changes the behavior of the Run function.

type UploadToContainerOptions

type UploadToContainerOptions struct {
	ContainerID, UploadPath, TarPath, Contents string
}

UploadToContainerOptions represents the parameters in a call to UploadToContainer.

Jump to

Keyboard shortcuts

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