docker

package
v0.0.0-...-3fa228a Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2016 License: MIT Imports: 12 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 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) Exec

func (dk Client) Exec(name string, cmd ...string) error

Exec executes a command within the container with the supplied name.

func (Client) ExecVerbose

func (dk Client) ExecVerbose(name string, cmd ...string) ([]byte, error)

ExecVerbose executes a command within the container with the supplied name. It also returns the output of that command.

func (Client) Get

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

Get returns a Container corresponding to the supplied ID.

func (Client) GetFromContainer

func (dk Client) GetFromContainer(id string, src string) (string, error)

GetFromContainer returns a string containing the content of the file named SRC on the container with id 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.

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.

func (Client) WriteToContainer

func (dk Client) WriteToContainer(id, src, dst, archiveName string,
	permission int) error

WriteToContainer writes the contents of SRC into the file at path DST on the container with id ID. Overwrites DST if it already exists.

type Container

type Container struct {
	ID     string
	Name   string
	Image  string
	IP     string
	Path   string
	Args   []string
	Pid    int
	Env    map[string]string
	Labels map[string]string
}

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
	Pulled     map[string]struct{}
	Containers map[string]mockContainer

	Executions map[string][]string

	CreateError     bool
	CreateExecError bool
	InspectError    bool
	ListError       bool
	PullError       bool
	RemoveError     bool
	StartError      bool
	StartExecError  bool
	// contains filtered or unexported fields
}

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

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) 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) ListContainers

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

ListContainers lists the running containers.

func (MockClient) PullImage

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

PullImage pulls the requested image.

func (MockClient) RemoveContainer

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

RemoveContainer removes the given docker container.

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 is not implemented.

type RunOptions

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

	NetworkMode string
	PidMode     string
	Privileged  bool
	VolumesFrom []string
}

RunOptions changes the behavior of the Run function.

Jump to

Keyboard shortcuts

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