docker

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2014 License: BSD-2-Clause, Apache-2.0 Imports: 20 Imported by: 0

README

#go-dockerclient

Build Status Build Status

GoDoc

This package presents a client for the Docker remote API.

For more details, check the remote API documentation.

Example

package main

import (
        "fmt"
        "github.com/fsouza/go-dockerclient"
)

func main() {
        endpoint := "unix:///var/run/docker.sock"
        client, _ := docker.NewClient(endpoint)
        imgs, _ := client.ListImages(true)
        for _, img := range imgs {
                fmt.Println("ID: ", img.ID)
                fmt.Println("RepoTags: ", img.RepoTags)
                fmt.Println("Created: ", img.Created)
                fmt.Println("Size: ", img.Size)
                fmt.Println("VirtualSize: ", img.VirtualSize)
                fmt.Println("ParentId: ", img.ParentId)
        }
}

Developing

You can run the tests with:

go get -d ./...
go test ./...

Documentation

Overview

Package docker provides a client for the Docker remote API.

See http://goo.gl/G3plxW for more details on the remote API.

Index

Examples

Constants

View Source
const (
	SIGABRT   = Signal(0x6)
	SIGALRM   = Signal(0xe)
	SIGBUS    = Signal(0x7)
	SIGCHLD   = Signal(0x11)
	SIGCLD    = Signal(0x11)
	SIGCONT   = Signal(0x12)
	SIGFPE    = Signal(0x8)
	SIGHUP    = Signal(0x1)
	SIGILL    = Signal(0x4)
	SIGINT    = Signal(0x2)
	SIGIO     = Signal(0x1d)
	SIGIOT    = Signal(0x6)
	SIGKILL   = Signal(0x9)
	SIGPIPE   = Signal(0xd)
	SIGPOLL   = Signal(0x1d)
	SIGPROF   = Signal(0x1b)
	SIGPWR    = Signal(0x1e)
	SIGQUIT   = Signal(0x3)
	SIGSEGV   = Signal(0xb)
	SIGSTKFLT = Signal(0x10)
	SIGSTOP   = Signal(0x13)
	SIGSYS    = Signal(0x1f)
	SIGTERM   = Signal(0xf)
	SIGTRAP   = Signal(0x5)
	SIGTSTP   = Signal(0x14)
	SIGTTIN   = Signal(0x15)
	SIGTTOU   = Signal(0x16)
	SIGUNUSED = Signal(0x1f)
	SIGURG    = Signal(0x17)
	SIGUSR1   = Signal(0xa)
	SIGUSR2   = Signal(0xc)
	SIGVTALRM = Signal(0x1a)
	SIGWINCH  = Signal(0x1c)
	SIGXCPU   = Signal(0x18)
	SIGXFSZ   = Signal(0x19)
)

These values represent all signals available on Linux, where containers will be running.

Variables

View Source
var (
	// ErrInvalidEndpoint is returned when the endpoint is not a valid HTTP URL.
	ErrInvalidEndpoint = errors.New("invalid endpoint")

	// ErrConnectionRefused is returned when the client cannot connect to the given endpoint.
	ErrConnectionRefused = errors.New("cannot connect to Docker endpoint")
)
View Source
var (
	// ErrNoListeners is the error returned when no listeners are available
	// to receive an event.
	ErrNoListeners = errors.New("no listeners present to receive event")

	// ErrListenerAlreadyExists is the error returned when the listerner already
	// exists.
	ErrListenerAlreadyExists = errors.New("listener already exists for docker events")
)
View Source
var (
	// ErrNoSuchImage is the error returned when the image does not exist.
	ErrNoSuchImage = errors.New("no such image")

	// ErrMissingRepo is the error returned when the remote repository is
	// missing.
	ErrMissingRepo = errors.New("missing remote repository e.g. 'github.com/user/repo'")

	// ErrMissingOutputStream is the error returned when no output stream
	// is provided to some calls, like BuildImage.
	ErrMissingOutputStream = errors.New("missing output stream")
)

Functions

func ParseRepositoryTag

func ParseRepositoryTag(repoTag string) (repository string, tag string)

ParseRepositoryTag gets the name of the repository and returns it splitted in two parts: the repository and the tag.

Some examples:

localhost.localdomain:5000/samalba/hipache:latest -> localhost.localdomain:5000/samalba/hipache, latest
localhost.localdomain:5000/samalba/hipache -> localhost.localdomain:5000/samalba/hipache, ""

Types

type APIContainers

type APIContainers struct {
	ID         string    `json:"Id" yaml:"Id"`
	Image      string    `json:"Image,omitempty" yaml:"Image,omitempty"`
	Command    string    `json:"Command,omitempty" yaml:"Command,omitempty"`
	Created    int64     `json:"Created,omitempty" yaml:"Created,omitempty"`
	Status     string    `json:"Status,omitempty" yaml:"Status,omitempty"`
	Ports      []APIPort `json:"Ports,omitempty" yaml:"Ports,omitempty"`
	SizeRw     int64     `json:"SizeRw,omitempty" yaml:"SizeRw,omitempty"`
	SizeRootFs int64     `json:"SizeRootFs,omitempty" yaml:"SizeRootFs,omitempty"`
	Names      []string  `json:"Names,omitempty" yaml:"Names,omitempty"`
}

APIContainers represents a container.

See http://goo.gl/QeFH7U for more details.

type APIEvents

type APIEvents struct {
	Status string `json:"Status,omitempty" yaml:"Status,omitempty"`
	ID     string `json:"ID,omitempty" yaml:"ID,omitempty"`
	From   string `json:"From,omitempty" yaml:"From,omitempty"`
	Time   int64  `json:"Time,omitempty" yaml:"Time,omitempty"`
}

APIEvents represents an event returned by the API.

type APIImageSearch added in v0.5.1

type APIImageSearch struct {
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	IsOfficial  bool   `json:"is_official,omitempty" yaml:"is_official,omitempty"`
	IsAutomated bool   `json:"is_automated,omitempty" yaml:"is_automated,omitempty"`
	Name        string `json:"name,omitempty" yaml:"name,omitempty"`
	StarCount   int    `json:"star_count,omitempty" yaml:"star_count,omitempty"`
}

APIImageSearch reflect the result of a search on the dockerHub

See http://goo.gl/xI5lLZ for more details.

type APIImages

type APIImages struct {
	ID          string   `json:"Id" yaml:"Id"`
	RepoTags    []string `json:"RepoTags,omitempty" yaml:"RepoTags,omitempty"`
	Created     int64    `json:"Created,omitempty" yaml:"Created,omitempty"`
	Size        int64    `json:"Size,omitempty" yaml:"Size,omitempty"`
	VirtualSize int64    `json:"VirtualSize,omitempty" yaml:"VirtualSize,omitempty"`
	ParentId    string   `json:"ParentId,omitempty" yaml:"ParentId,omitempty"`
}

APIImages represent an image returned in the ListImages call.

type APIPort

type APIPort struct {
	PrivatePort int64  `json:"PrivatePort,omitempty" yaml:"PrivatePort,omitempty"`
	PublicPort  int64  `json:"PublicPort,omitempty" yaml:"PublicPort,omitempty"`
	Type        string `json:"Type,omitempty" yaml:"Type,omitempty"`
	IP          string `json:"IP,omitempty" yaml:"IP,omitempty"`
}

type ApiVersion

type ApiVersion []int

ApiVersion is an internal representation of a version of the Remote API.

func NewApiVersion

func NewApiVersion(input string) (ApiVersion, error)

NewApiVersion returns an instance of ApiVersion for the given string.

The given string must be in the form <major>.<minor>.<patch>, where <major>, <minor> and <patch> are integer numbers.

func (ApiVersion) GreaterThan

func (version ApiVersion) GreaterThan(other ApiVersion) bool

func (ApiVersion) GreaterThanOrEqualTo

func (version ApiVersion) GreaterThanOrEqualTo(other ApiVersion) bool

func (ApiVersion) LessThan

func (version ApiVersion) LessThan(other ApiVersion) bool

func (ApiVersion) LessThanOrEqualTo

func (version ApiVersion) LessThanOrEqualTo(other ApiVersion) bool

func (ApiVersion) String

func (version ApiVersion) String() string

type AttachToContainerOptions

type AttachToContainerOptions struct {
	Container    string    `qs:"-"`
	InputStream  io.Reader `qs:"-"`
	OutputStream io.Writer `qs:"-"`
	ErrorStream  io.Writer `qs:"-"`

	// Get container logs, sending it to OutputStream.
	Logs bool

	// Stream the response?
	Stream bool

	// Attach to stdin, and use InputStream.
	Stdin bool

	// Attach to stdout, and use OutputStream.
	Stdout bool

	// Attach to stderr, and use ErrorStream.
	Stderr bool

	// If set, after a successful connect, a sentinel will be sent and then the
	// client will block on receive before continuing.
	//
	// It must be an unbuffered channel. Using a buffered channel can lead
	// to unexpected behavior.
	Success chan struct{}

	// Use raw terminal? Usually true when the container contains a TTY.
	RawTerminal bool `qs:"-"`
}

AttachToContainerOptions is the set of options that can be used when attaching to a container.

See http://goo.gl/RRAhws for more details.

type AuthConfiguration

type AuthConfiguration struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	Email    string `json:"email,omitempty"`
}

AuthConfiguration represents authentication options to use in the PushImage method. It represents the authentication in the Docker index server.

type BuildImageOptions

type BuildImageOptions struct {
	Name                string    `qs:"t"`
	NoCache             bool      `qs:"nocache"`
	SuppressOutput      bool      `qs:"q"`
	RmTmpContainer      bool      `qs:"rm"`
	ForceRmTmpContainer bool      `qs:"forcerm"`
	InputStream         io.Reader `qs:"-"`
	OutputStream        io.Writer `qs:"-"`
	RawJSONStream       bool      `qs:"-"`
	Remote              string    `qs:"remote"`
}

BuildImageOptions present the set of informations available for building an image from a tarfile with a Dockerfile in it.

For more details about the Docker building process, see http://goo.gl/tlPXPu.

type Change

type Change struct {
	Path string
	Kind ChangeType
}

Change represents a change in a container.

See http://goo.gl/QkW9sH for more details.

func (*Change) String

func (change *Change) String() string

type ChangeType

type ChangeType int
const (
	ChangeModify ChangeType = iota
	ChangeAdd
	ChangeDelete
)

type Client

type Client struct {
	SkipServerVersionCheck bool
	HTTPClient             *http.Client
	// contains filtered or unexported fields
}

Client is the basic type of this package. It provides methods for interaction with the API.

func NewClient

func NewClient(endpoint string) (*Client, error)

NewClient returns a Client instance ready for communication with the given server endpoint. It will use the latest remote API version available in the server.

func NewVersionedClient

func NewVersionedClient(endpoint string, apiVersionString string) (*Client, error)

NewVersionedClient returns a Client instance ready for communication with the given server endpoint, using a specific remote API version.

func (*Client) AddEventListener

func (c *Client) AddEventListener(listener chan<- *APIEvents) error

AddEventListener adds a new listener to container events in the Docker API.

The parameter is a channel through which events will be sent.

func (*Client) AttachToContainer

func (c *Client) AttachToContainer(opts AttachToContainerOptions) error

AttachToContainer attaches to a container, using the given options.

See http://goo.gl/RRAhws for more details.

Example
client, err := docker.NewClient("http://localhost:4243")
if err != nil {
	log.Fatal(err)
}
client.SkipServerVersionCheck = true
// Reading logs from container a84849 and sending them to buf.
var buf bytes.Buffer
err = client.AttachToContainer(docker.AttachToContainerOptions{
	Container:    "a84849",
	OutputStream: &buf,
	Logs:         true,
	Stdout:       true,
	Stderr:       true,
})
if err != nil {
	log.Fatal(err)
}
log.Println(buf.String())
buf.Reset()
err = client.AttachToContainer(docker.AttachToContainerOptions{
	Container:    "a84849",
	OutputStream: &buf,
	Stdout:       true,
	Stream:       true,
})
if err != nil {
	log.Fatal(err)
}
log.Println(buf.String())
Output:

func (*Client) BuildImage

func (c *Client) BuildImage(opts BuildImageOptions) error

BuildImage builds an image from a tarball's url or a Dockerfile in the input stream.

See http://goo.gl/wRsW76 for more details.

Example
client, err := docker.NewClient("http://localhost:4243")
if err != nil {
	log.Fatal(err)
}

t := time.Now()
inputbuf, outputbuf := bytes.NewBuffer(nil), bytes.NewBuffer(nil)
tr := tar.NewWriter(inputbuf)
tr.WriteHeader(&tar.Header{Name: "Dockerfile", Size: 10, ModTime: t, AccessTime: t, ChangeTime: t})
tr.Write([]byte("FROM base\n"))
tr.Close()
opts := docker.BuildImageOptions{
	Name:         "test",
	InputStream:  inputbuf,
	OutputStream: outputbuf,
}
if err := client.BuildImage(opts); err != nil {
	log.Fatal(err)
}
Output:

func (*Client) CommitContainer

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

CommitContainer creates a new image from a container's changes.

See http://goo.gl/Jn8pe8 for more details.

func (*Client) ContainerChanges

func (c *Client) ContainerChanges(id string) ([]Change, error)

ContainerChanges returns changes in the filesystem of the given container.

See http://goo.gl/QkW9sH for more details.

func (*Client) CopyFromContainer

func (c *Client) CopyFromContainer(opts CopyFromContainerOptions) error

CopyFromContainer copy files or folders from a container, using a given resource.

See http://goo.gl/rINMlw for more details.

Example
client, err := docker.NewClient("http://localhost:4243")
if err != nil {
	log.Fatal(err)
}
cid := "a84849"
var buf bytes.Buffer
filename := "/tmp/output.txt"
err = client.CopyFromContainer(docker.CopyFromContainerOptions{
	Container:    cid,
	Resource:     filename,
	OutputStream: &buf,
})
if err != nil {
	log.Fatalf("Error while copying from %s: %s\n", cid, err)
}
content := new(bytes.Buffer)
r := bytes.NewReader(buf.Bytes())
tr := tar.NewReader(r)
tr.Next()
if err != nil && err != io.EOF {
	log.Fatal(err)
}
if _, err := io.Copy(content, tr); err != nil {
	log.Fatal(err)
}
log.Println(buf.String())
Output:

func (*Client) CreateContainer

func (c *Client) CreateContainer(opts CreateContainerOptions) (*Container, error)

CreateContainer creates a new container, returning the container instance, or an error in case of failure.

See http://goo.gl/mErxNp for more details.

func (*Client) CreateExec added in v0.5.1

func (c *Client) CreateExec(opts CreateExecOptions) (*Exec, error)

CreateExec sets up an exec instance in a running container `id`, returning the exec instance, or an error in case of failure.

See http://goo.gl/8izrzI for more details

func (*Client) ExportContainer

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

ExportContainer export the contents of container id as tar archive and prints the exported contents to stdout.

See http://goo.gl/hnzE62 for more details.

func (*Client) ExportImage

func (c *Client) ExportImage(opts ExportImageOptions) error

ExportImage exports an image (as a tar file) into the stream

See http://goo.gl/mi6kvk for more details.

func (*Client) ImageHistory added in v0.5.1

func (c *Client) ImageHistory(name string) ([]ImageHistory, error)

ImageHistory returns the history of the image by its name or ID.

See http://goo.gl/2oJmNs for more details.

func (*Client) ImportImage

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

ImportImage imports an image from a url, a file or stdin

See http://goo.gl/PhBKnS for more details.

func (*Client) Info

func (c *Client) Info() (*Env, error)

Info returns system-wide information about the Docker server.

See http://goo.gl/wmqZsW for more details.

func (*Client) InspectContainer

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

InspectContainer returns information about a container by its ID.

See http://goo.gl/CxVuJ5 for more details.

func (*Client) InspectImage

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

InspectImage returns an image by its name or ID.

See http://goo.gl/Q112NY for more details.

func (*Client) KillContainer

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

KillContainer kills a container, returning an error in case of failure.

See http://goo.gl/TFkECx for more details.

func (*Client) ListContainers

func (c *Client) ListContainers(opts ListContainersOptions) ([]APIContainers, error)

ListContainers returns a slice of containers matching the given criteria.

See http://goo.gl/XqtcyU for more details.

func (*Client) ListImages

func (c *Client) ListImages(all bool) ([]APIImages, error)

ListImages returns the list of available images in the server.

See http://goo.gl/VmcR6v for more details.

func (*Client) LoadImage

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

LoadImage imports a tarball docker image

See http://goo.gl/Y8NNCq for more details.

func (*Client) Logs

func (c *Client) Logs(opts LogsOptions) error

Logs gets stdout and stderr logs from the specified container.

See http://goo.gl/rLhKSU for more details.

func (*Client) PauseContainer

func (c *Client) PauseContainer(id string) error

PauseContainer pauses the given container.

See http://goo.gl/AM5t42 for more details.

func (*Client) Ping

func (c *Client) Ping() error

Ping pings the docker server

See http://goo.gl/stJENm for more details.

func (*Client) PullImage

func (c *Client) PullImage(opts PullImageOptions, auth AuthConfiguration) error

PullImage pulls an image from a remote registry, logging progress to w.

See http://goo.gl/ACyYNS for more details.

func (*Client) PushImage

func (c *Client) PushImage(opts PushImageOptions, auth AuthConfiguration) error

PushImage pushes an image to a remote registry, logging progress to w.

An empty instance of AuthConfiguration may be used for unauthenticated pushes.

See http://goo.gl/pN8A3P for more details.

func (*Client) RemoveContainer

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

RemoveContainer removes a container, returning an error in case of failure.

See http://goo.gl/ZB83ji for more details.

func (*Client) RemoveEventListener

func (c *Client) RemoveEventListener(listener chan *APIEvents) error

RemoveEventListener removes a listener from the monitor.

func (*Client) RemoveImage

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

RemoveImage removes an image by its name or ID.

See http://goo.gl/znj0wM for more details.

func (*Client) ResizeContainerTTY

func (c *Client) ResizeContainerTTY(id string, height, width int) error

ResizeContainerTTY resizes the terminal to the given height and width.

func (*Client) ResizeExecTTY added in v0.5.1

func (c *Client) ResizeExecTTY(id string, height, width int) error

Resizes the tty session used by the exec command id. This API is valid only if Tty was specified as part of creating and starting the exec command.

See http://goo.gl/YDSx1f for more details

func (*Client) RestartContainer

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

RestartContainer stops a container, killing it after the given timeout (in seconds), during the stop process.

See http://goo.gl/VOzR2n for more details.

func (*Client) SearchImages added in v0.5.1

func (c *Client) SearchImages(term string) ([]APIImageSearch, error)

SearchImages search the docker hub with a specific given term.

See http://goo.gl/xI5lLZ for more details.

func (*Client) StartContainer

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

StartContainer starts a container, returning an error in case of failure.

See http://goo.gl/iM5GYs for more details.

func (*Client) StartExec added in v0.5.1

func (c *Client) StartExec(id string, opts StartExecOptions) error

Starts a previously set up exec instance id. If opts.Detach is true, it returns after starting the exec command. Otherwise, it sets up an interactive session with the exec command.

See http://goo.gl/JW8Lxl for more details

func (*Client) StopContainer

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

StopContainer stops a container, killing it after the given timeout (in seconds).

See http://goo.gl/EbcpXt for more details.

func (*Client) TagImage

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

TagImage adds a tag to the image identified by the given name.

See http://goo.gl/5g6qFy for more details.

func (*Client) TopContainer added in v0.5.1

func (c *Client) TopContainer(id string, psArgs string) (TopResult, error)

TopContainer returns processes running inside a container

See http://goo.gl/qu4gse for more details.

func (*Client) UnpauseContainer

func (c *Client) UnpauseContainer(id string) error

UnpauseContainer pauses the given container.

See http://goo.gl/eBrNSL for more details.

func (*Client) Version

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

Version returns version information about the docker server.

See http://goo.gl/BOZrF5 for more details.

func (*Client) WaitContainer

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

WaitContainer blocks until the given container stops, return the exit code of the container status.

See http://goo.gl/J88DHU for more details.

type CommitContainerOptions

type CommitContainerOptions struct {
	Container  string
	Repository string `qs:"repo"`
	Tag        string
	Message    string `qs:"m"`
	Author     string
	Run        *Config `qs:"-"`
}

CommitContainerOptions aggregates parameters to the CommitContainer method.

See http://goo.gl/Jn8pe8 for more details.

type Config

type Config struct {
	Hostname        string              `json:"Hostname,omitempty" yaml:"Hostname,omitempty"`
	Domainname      string              `json:"Domainname,omitempty" yaml:"Domainname,omitempty"`
	User            string              `json:"User,omitempty" yaml:"User,omitempty"`
	Memory          int64               `json:"Memory,omitempty" yaml:"Memory,omitempty"`
	MemorySwap      int64               `json:"MemorySwap,omitempty" yaml:"MemorySwap,omitempty"`
	CpuShares       int64               `json:"CpuShares,omitempty" yaml:"CpuShares,omitempty"`
	CpuSet          string              `json:"CpuSet,omitempty" yaml:"CpuSet,omitempty"`
	AttachStdin     bool                `json:"AttachStdin,omitempty" yaml:"AttachStdin,omitempty"`
	AttachStdout    bool                `json:"AttachStdout,omitempty" yaml:"AttachStdout,omitempty"`
	AttachStderr    bool                `json:"AttachStderr,omitempty" yaml:"AttachStderr,omitempty"`
	PortSpecs       []string            `json:"PortSpecs,omitempty" yaml:"PortSpecs,omitempty"`
	ExposedPorts    map[Port]struct{}   `json:"ExposedPorts,omitempty" yaml:"ExposedPorts,omitempty"`
	Tty             bool                `json:"Tty,omitempty" yaml:"Tty,omitempty"`
	OpenStdin       bool                `json:"OpenStdin,omitempty" yaml:"OpenStdin,omitempty"`
	StdinOnce       bool                `json:"StdinOnce,omitempty" yaml:"StdinOnce,omitempty"`
	Env             []string            `json:"Env,omitempty" yaml:"Env,omitempty"`
	Cmd             []string            `json:"Cmd,omitempty" yaml:"Cmd,omitempty"`
	Dns             []string            `json:"Dns,omitempty" yaml:"Dns,omitempty"` // For Docker API v1.9 and below only
	Image           string              `json:"Image,omitempty" yaml:"Image,omitempty"`
	Volumes         map[string]struct{} `json:"Volumes,omitempty" yaml:"Volumes,omitempty"`
	VolumesFrom     string              `json:"VolumesFrom,omitempty" yaml:"VolumesFrom,omitempty"`
	WorkingDir      string              `json:"WorkingDir,omitempty" yaml:"WorkingDir,omitempty"`
	Entrypoint      []string            `json:"Entrypoint,omitempty" yaml:"Entrypoint,omitempty"`
	NetworkDisabled bool                `json:"NetworkDisabled,omitempty" yaml:"NetworkDisabled,omitempty"`
}

type Container

type Container struct {
	ID string `json:"Id" yaml:"Id"`

	Created time.Time `json:"Created,omitempty" yaml:"Created,omitempty"`

	Path string   `json:"Path,omitempty" yaml:"Path,omitempty"`
	Args []string `json:"Args,omitempty" yaml:"Args,omitempty"`

	Config *Config `json:"Config,omitempty" yaml:"Config,omitempty"`
	State  State   `json:"State,omitempty" yaml:"State,omitempty"`
	Image  string  `json:"Image,omitempty" yaml:"Image,omitempty"`

	NetworkSettings *NetworkSettings `json:"NetworkSettings,omitempty" yaml:"NetworkSettings,omitempty"`

	SysInitPath    string `json:"SysInitPath,omitempty" yaml:"SysInitPath,omitempty"`
	ResolvConfPath string `json:"ResolvConfPath,omitempty" yaml:"ResolvConfPath,omitempty"`
	HostnamePath   string `json:"HostnamePath,omitempty" yaml:"HostnamePath,omitempty"`
	HostsPath      string `json:"HostsPath,omitempty" yaml:"HostsPath,omitempty"`
	Name           string `json:"Name,omitempty" yaml:"Name,omitempty"`
	Driver         string `json:"Driver,omitempty" yaml:"Driver,omitempty"`

	Volumes    map[string]string `json:"Volumes,omitempty" yaml:"Volumes,omitempty"`
	VolumesRW  map[string]bool   `json:"VolumesRW,omitempty" yaml:"VolumesRW,omitempty"`
	HostConfig *HostConfig       `json:"HostConfig,omitempty" yaml:"HostConfig,omitempty"`
}

type ContainerAlreadyRunning

type ContainerAlreadyRunning struct {
	ID string
}

ContainerAlreadyRunning is the error returned when a given container is already running.

func (*ContainerAlreadyRunning) Error

func (err *ContainerAlreadyRunning) Error() string

type ContainerNotRunning

type ContainerNotRunning struct {
	ID string
}

ContainerNotRunning is the error returned when a given container is not running.

func (*ContainerNotRunning) Error

func (err *ContainerNotRunning) Error() string

type CopyFromContainerOptions

type CopyFromContainerOptions struct {
	OutputStream io.Writer `json:"-"`
	Container    string    `json:"-"`
	Resource     string
}

CopyFromContainerOptions is the set of options that can be used when copying files or folders from a container.

See http://goo.gl/rINMlw for more details.

type CreateContainerOptions

type CreateContainerOptions struct {
	Name   string
	Config *Config `qs:"-"`
}

CreateContainerOptions specify parameters to the CreateContainer function.

See http://goo.gl/mErxNp for more details.

type CreateExecOptions added in v0.5.1

type CreateExecOptions struct {
	AttachStdin  bool     `json:"AttachStdin,omitempty" yaml:"AttachStdin,omitempty"`
	AttachStdout bool     `json:"AttachStdout,omitempty" yaml:"AttachStdout,omitempty"`
	AttachStderr bool     `json:"AttachStderr,omitempty" yaml:"AttachStderr,omitempty"`
	Tty          bool     `json:"Tty,omitempty" yaml:"Tty,omitempty"`
	Cmd          []string `json:"Cmd,omitempty" yaml:"Cmd,omitempty"`
	Container    string   `json:"Container,omitempty" yaml:"Container,omitempty"`
}

CreateExecOptions specify parameters to the CreateExecContainer function.

See http://goo.gl/8izrzI for more details

type Env

type Env []string

Env represents a list of key-pair represented in the form KEY=VALUE.

func (*Env) Decode

func (env *Env) Decode(src io.Reader) error

Decode decodes `src` as a json dictionary, and adds each decoded key-value pair to the environment.

If `src` cannot be decoded as a json dictionary, an error is returned.

func (*Env) Exists

func (env *Env) Exists(key string) bool

Exists checks whether the given key is defined in the internal Env representation.

func (*Env) Get

func (env *Env) Get(key string) (value string)

Get returns the string value of the given key.

func (*Env) GetBool

func (env *Env) GetBool(key string) (value bool)

GetBool returns a boolean representation of the given key. The key is false whenever its value if 0, no, false, none or an empty string. Any other value will be interpreted as true.

func (*Env) GetInt

func (env *Env) GetInt(key string) int

GetInt returns the value of the provided key, converted to int.

It the value cannot be represented as an integer, it returns -1.

func (*Env) GetInt64

func (env *Env) GetInt64(key string) int64

GetInt64 returns the value of the provided key, converted to int64.

It the value cannot be represented as an integer, it returns -1.

func (*Env) GetJSON

func (env *Env) GetJSON(key string, iface interface{}) error

GetJSON unmarshals the value of the provided key in the provided iface.

iface is a value that can be provided to the json.Unmarshal function.

Example
type Person struct {
	Name string
	Age  int
}
p := Person{Name: "Gopher", Age: 4}
var e docker.Env
e.Set("person", `{"name":"Gopher","age":4}`)
err := e.GetJSON("person", &p)
if err != nil {
	log.Fatal(err)
}
Output:

func (*Env) GetList

func (env *Env) GetList(key string) []string

GetList returns a list of strings matching the provided key. It handles the list as a JSON representation of a list of strings.

If the given key matches to a single string, it will return a list containing only the value that matches the key.

func (*Env) Map

func (env *Env) Map() map[string]string

Map returns the map representation of the env.

Example
e := docker.Env([]string{"A=1", "B=2", "C=3"})
envs := e.Map()
for k, v := range envs {
	fmt.Printf("%s=%q\n", k, v)
}
Output:

func (*Env) Set

func (env *Env) Set(key, value string)

Set defines the value of a key to the given string.

func (*Env) SetAuto

func (env *Env) SetAuto(key string, value interface{})

SetAuto will try to define the Set* method to call based on the given value.

func (*Env) SetBool

func (env *Env) SetBool(key string, value bool)

SetBool defines a boolean value to the given key.

func (*Env) SetInt

func (env *Env) SetInt(key string, value int)

SetInt defines an integer value to the given key.

func (*Env) SetInt64

func (env *Env) SetInt64(key string, value int64)

SetInt64 defines an integer (64-bit wide) value to the given key.

func (*Env) SetJSON

func (env *Env) SetJSON(key string, value interface{}) error

SetJSON marshals the given value to JSON format and stores it using the provided key.

Example
type Person struct {
	Name string
	Age  int
}
p := Person{Name: "Gopher", Age: 4}
var e docker.Env
err := e.SetJSON("person", p)
if err != nil {
	log.Fatal(err)
}
Output:

func (*Env) SetList

func (env *Env) SetList(key string, value []string) error

SetList stores the given list in the provided key, after serializing it to JSON format.

type Error

type Error struct {
	Status  int
	Message string
}

Error represents failures in the API. It represents a failure from the API.

func (*Error) Error

func (e *Error) Error() string

type Exec added in v0.5.1

type Exec struct {
	Id string `json:"Id,omitempty" yaml:"Id,omitempty"`
}

type ExportContainerOptions

type ExportContainerOptions struct {
	ID           string
	OutputStream io.Writer
}

ExportContainerOptions is the set of parameters to the ExportContainer method.

See http://goo.gl/hnzE62 for more details.

type ExportImageOptions

type ExportImageOptions struct {
	Name         string
	OutputStream io.Writer
}

ExportImageOptions represent the options for ExportImage Docker API call

See http://goo.gl/mi6kvk for more details.

type HostConfig

type HostConfig struct {
	Binds           []string               `json:"Binds,omitempty" yaml:"Binds,omitempty"`
	CapAdd          []string               `json:"CapAdd,omitempty" yaml:"CapAdd,omitempty"`
	CapDrop         []string               `json:"CapDrop,omitempty" yaml:"CapDrop,omitempty"`
	ContainerIDFile string                 `json:"ContainerIDFile,omitempty" yaml:"ContainerIDFile,omitempty"`
	LxcConf         []KeyValuePair         `json:"LxcConf,omitempty" yaml:"LxcConf,omitempty"`
	Privileged      bool                   `json:"Privileged,omitempty" yaml:"Privileged,omitempty"`
	PortBindings    map[Port][]PortBinding `json:"PortBindings,omitempty" yaml:"PortBindings,omitempty"`
	Links           []string               `json:"Links,omitempty" yaml:"Links,omitempty"`
	PublishAllPorts bool                   `json:"PublishAllPorts,omitempty" yaml:"PublishAllPorts,omitempty"`
	Dns             []string               `json:"Dns,omitempty" yaml:"Dns,omitempty"` // For Docker API v1.10 and above only
	DnsSearch       []string               `json:"DnsSearch,omitempty" yaml:"DnsSearch,omitempty"`
	VolumesFrom     []string               `json:"VolumesFrom,omitempty" yaml:"VolumesFrom,omitempty"`
	NetworkMode     string                 `json:"NetworkMode,omitempty" yaml:"NetworkMode,omitempty"`
	RestartPolicy   RestartPolicy          `json:"RestartPolicy,omitempty" yaml:"RestartPolicy,omitempty"`
}

type Image

type Image struct {
	ID              string    `json:"Id" yaml:"Id"`
	Parent          string    `json:"Parent,omitempty" yaml:"Parent,omitempty"`
	Comment         string    `json:"Comment,omitempty" yaml:"Comment,omitempty"`
	Created         time.Time `json:"Created,omitempty" yaml:"Created,omitempty"`
	Container       string    `json:"Container,omitempty" yaml:"Container,omitempty"`
	ContainerConfig Config    `json:"ContainerConfig,omitempty" yaml:"ContainerConfig,omitempty"`
	DockerVersion   string    `json:"DockerVersion,omitempty" yaml:"DockerVersion,omitempty"`
	Author          string    `json:"Author,omitempty" yaml:"Author,omitempty"`
	Config          *Config   `json:"Config,omitempty" yaml:"Config,omitempty"`
	Architecture    string    `json:"Architecture,omitempty" yaml:"Architecture,omitempty"`
	Size            int64     `json:"Size,omitempty" yaml:"Size,omitempty"`
}

type ImageHistory added in v0.5.1

type ImageHistory struct {
	ID        string   `json:"Id" yaml:"Id"`
	Tags      []string `json:"Tags,omitempty" yaml:"Tags,omitempty"`
	Created   int64    `json:"Created,omitempty" yaml:"Created,omitempty"`
	CreatedBy string   `json:"CreatedBy,omitempty" yaml:"CreatedBy,omitempty"`
	Size      int64    `json:"Size,omitempty" yaml:"Size,omitempty"`
}

ImageHistory represent a layer in an image's history returned by the ImageHistory call.

type ImagePre012

type ImagePre012 struct {
	ID              string    `json:"id"`
	Parent          string    `json:"parent,omitempty"`
	Comment         string    `json:"comment,omitempty"`
	Created         time.Time `json:"created"`
	Container       string    `json:"container,omitempty"`
	ContainerConfig Config    `json:"container_config,omitempty"`
	DockerVersion   string    `json:"docker_version,omitempty"`
	Author          string    `json:"author,omitempty"`
	Config          *Config   `json:"config,omitempty"`
	Architecture    string    `json:"architecture,omitempty"`
	Size            int64     `json:"size,omitempty"`
}

type ImportImageOptions

type ImportImageOptions struct {
	Repository string `qs:"repo"`
	Source     string `qs:"fromSrc"`
	Tag        string `qs:"tag"`

	InputStream  io.Reader `qs:"-"`
	OutputStream io.Writer `qs:"-"`
}

ImportImageOptions present the set of informations available for importing an image from a source file or the stdin.

See http://goo.gl/PhBKnS for more details.

type KeyValuePair

type KeyValuePair struct {
	Key   string `json:"Key,omitempty" yaml:"Key,omitempty"`
	Value string `json:"Value,omitempty" yaml:"Value,omitempty"`
}

type KillContainerOptions

type KillContainerOptions struct {
	// The ID of the container.
	ID string `qs:"-"`

	// The signal to send to the container. When omitted, Docker server
	// will assume SIGKILL.
	Signal Signal
}

KillContainerOptions represents the set of options that can be used in a call to KillContainer.

See http://goo.gl/TFkECx for more details.

type ListContainersOptions

type ListContainersOptions struct {
	All    bool
	Size   bool
	Limit  int
	Since  string
	Before string
}

ListContainersOptions specify parameters to the ListContainers function.

See http://goo.gl/XqtcyU for more details.

type LoadImageOptions

type LoadImageOptions struct {
	InputStream io.Reader
}

LoadImageOptions represents the options for LoadImage Docker API Call

See http://goo.gl/Y8NNCq for more details.

type LogsOptions

type LogsOptions struct {
	Container    string    `qs:"-"`
	OutputStream io.Writer `qs:"-"`
	ErrorStream  io.Writer `qs:"-"`
	Follow       bool
	Stdout       bool
	Stderr       bool
	Timestamps   bool
	Tail         string

	// Use raw terminal? Usually true when the container contains a TTY.
	RawTerminal bool `qs:"-"`
}

LogsOptions represents the set of options used when getting logs from a container.

See http://goo.gl/rLhKSU for more details.

type NetworkSettings

type NetworkSettings struct {
	IPAddress   string                 `json:"IPAddress,omitempty" yaml:"IPAddress,omitempty"`
	IPPrefixLen int                    `json:"IPPrefixLen,omitempty" yaml:"IPPrefixLen,omitempty"`
	Gateway     string                 `json:"Gateway,omitempty" yaml:"Gateway,omitempty"`
	Bridge      string                 `json:"Bridge,omitempty" yaml:"Bridge,omitempty"`
	PortMapping map[string]PortMapping `json:"PortMapping,omitempty" yaml:"PortMapping,omitempty"`
	Ports       map[Port][]PortBinding `json:"Ports,omitempty" yaml:"Ports,omitempty"`
}

func (*NetworkSettings) PortMappingAPI

func (settings *NetworkSettings) PortMappingAPI() []APIPort

type NoSuchContainer

type NoSuchContainer struct {
	ID string
}

NoSuchContainer is the error returned when a given container does not exist.

func (*NoSuchContainer) Error

func (err *NoSuchContainer) Error() string

type NoSuchExec added in v0.5.1

type NoSuchExec struct {
	ID string
}

NoSuchExec is the error returned when a given exec instance does not exist.

func (*NoSuchExec) Error added in v0.5.1

func (err *NoSuchExec) Error() string

type Port

type Port string

Port represents the port number and the protocol, in the form <number>/<protocol>. For example: 80/tcp.

func (Port) Port

func (p Port) Port() string

Port returns the number of the port.

func (Port) Proto

func (p Port) Proto() string

Proto returns the name of the protocol.

type PortBinding

type PortBinding struct {
	HostIp   string `json:"HostIP,omitempty" yaml:"HostIP,omitempty"`
	HostPort string `json:"HostPort,omitempty" yaml:"HostPort,omitempty"`
}

type PortMapping

type PortMapping map[string]string

type PullImageOptions

type PullImageOptions struct {
	Repository    string `qs:"fromImage"`
	Registry      string
	Tag           string
	OutputStream  io.Writer `qs:"-"`
	RawJSONStream bool      `qs:"-"`
}

PullImageOptions present the set of options available for pulling an image from a registry.

See http://goo.gl/ACyYNS for more details.

type PushImageOptions

type PushImageOptions struct {
	// Name of the image
	Name string

	// Tag of the image
	Tag string

	// Registry server to push the image
	Registry string

	OutputStream  io.Writer `qs:"-"`
	RawJSONStream bool      `qs:"-"`
}

PushImageOptions represents options to use in the PushImage method.

See http://goo.gl/pN8A3P for more details.

type RemoveContainerOptions

type RemoveContainerOptions struct {
	// The ID of the container.
	ID string `qs:"-"`

	// A flag that indicates whether Docker should remove the volumes
	// associated to the container.
	RemoveVolumes bool `qs:"v"`

	// A flag that indicates whether Docker should remove the container
	// even if it is currently running.
	Force bool
}

RemoveContainerOptions encapsulates options to remove a container.

See http://goo.gl/ZB83ji for more details.

type RestartPolicy

type RestartPolicy struct {
	Name              string `json:"Name,omitempty" yaml:"Name,omitempty"`
	MaximumRetryCount int    `json:"MaximumRetryCount,omitempty" yaml:"MaximumRetryCount,omitempty"`
}

RestartPolicy represents the policy for automatically restarting a container.

Possible values are:

  • always: the docker daemon will always restart the container
  • on-failure: the docker daemon will restart the container on failures, at most MaximumRetryCount times
  • no: the docker daemon will not restart the container automatically

func AlwaysRestart

func AlwaysRestart() RestartPolicy

AlwaysRestart returns a restart policy that tells the Docker daemon to always restart the container.

func NeverRestart

func NeverRestart() RestartPolicy

NeverRestart returns a restart policy that tells the Docker daemon to never restart the container on failures.

func RestartOnFailure

func RestartOnFailure(maxRetry int) RestartPolicy

RestartOnFailure returns a restart policy that tells the Docker daemon to restart the container on failures, trying at most maxRetry times.

type Signal

type Signal int

Signal represents a signal that can be send to the container on KillContainer call.

type StartExecOptions added in v0.5.1

type StartExecOptions struct {
	Detach bool `json:"Detach,omitempty" yaml:"Detach,omitempty"`

	Tty bool `json:"Tty,omitempty" yaml:"Tty,omitempty"`

	InputStream  io.Reader `qs:"-"`
	OutputStream io.Writer `qs:"-"`
	ErrorStream  io.Writer `qs:"-"`

	// Use raw terminal? Usually true when the container contains a TTY.
	RawTerminal bool `qs:"-"`

	// If set, after a successful connect, a sentinel will be sent and then the
	// client will block on receive before continuing.
	//
	// It must be an unbuffered channel. Using a buffered channel can lead
	// to unexpected behavior.
	Success chan struct{} `json:"-"`
}

StartExecOptions specify parameters to the StartExecContainer function.

See http://goo.gl/JW8Lxl for more details

type State

type State struct {
	Running    bool      `json:"Running,omitempty" yaml:"Running,omitempty"`
	Paused     bool      `json:"Paused,omitempty" yaml:"Paused,omitempty"`
	Pid        int       `json:"Pid,omitempty" yaml:"Pid,omitempty"`
	ExitCode   int       `json:"ExitCode,omitempty" yaml:"ExitCode,omitempty"`
	StartedAt  time.Time `json:"StartedAt,omitempty" yaml:"StartedAt,omitempty"`
	FinishedAt time.Time `json:"FinishedAt,omitempty" yaml:"FinishedAt,omitempty"`
}

State represents the state of a container.

func (*State) String

func (s *State) String() string

String returns the string representation of a state.

type TagImageOptions

type TagImageOptions struct {
	Repo  string
	Tag   string
	Force bool
}

TagImageOptions present the set of options to tag an image.

See http://goo.gl/5g6qFy for more details.

type TopResult added in v0.5.1

type TopResult struct {
	Titles    []string
	Processes [][]string
}

TopResult represents the list of processes running in a container, as returned by /containers/<id>/top.

See http://goo.gl/qu4gse for more details.

Directories

Path Synopsis
Package testing provides a fake implementation of the Docker API, useful for testing purpose.
Package testing provides a fake implementation of the Docker API, useful for testing purpose.

Jump to

Keyboard shortcuts

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