Documentation ¶
Overview ¶
Package docker provides a client for the Docker remote API.
See http://goo.gl/mxyql for more details on the remote API.
Index ¶
- Constants
- Variables
- type APIContainers
- type APIEvents
- type APIImages
- type APIPort
- type ApiVersion
- type AttachToContainerOptions
- type AuthConfiguration
- type BuildImageOptions
- type Change
- type ChangeType
- type Client
- func (c *Client) AddEventListener(listener chan<- *APIEvents) error
- func (c *Client) AttachToContainer(opts AttachToContainerOptions) error
- func (c *Client) BuildImage(opts BuildImageOptions) error
- func (c *Client) CommitContainer(opts CommitContainerOptions) (*Image, error)
- func (c *Client) ContainerChanges(id string) ([]Change, error)
- func (c *Client) CopyFromContainer(opts CopyFromContainerOptions) error
- func (c *Client) CreateContainer(opts CreateContainerOptions) (*Container, error)
- func (c *Client) ExportContainer(opts ExportContainerOptions) error
- func (c *Client) ImportImage(opts ImportImageOptions) error
- func (c *Client) Info() (*engine.Env, error)
- func (c *Client) InspectContainer(id string) (*Container, error)
- func (c *Client) InspectImage(name string) (*Image, error)
- func (c *Client) KillContainer(opts KillContainerOptions) error
- func (c *Client) ListContainers(opts ListContainersOptions) ([]APIContainers, error)
- func (c *Client) ListImages(all bool) ([]APIImages, error)
- func (c *Client) LoadImages(inputStream io.Reader) error
- func (c *Client) Logs(opts LogsOptions) error
- func (c *Client) MonitorEvents() (EventMonitor, error)
- func (c *Client) PullImage(opts PullImageOptions, auth AuthConfiguration) error
- func (c *Client) PushImage(opts PushImageOptions, auth AuthConfiguration) error
- func (c *Client) RemoveContainer(opts RemoveContainerOptions) error
- func (c *Client) RemoveEventListener(listener chan *APIEvents) error
- func (c *Client) RemoveImage(name string) error
- func (c *Client) ResizeContainerTTY(id string, height, width int) error
- func (c *Client) RestartContainer(id string, timeout uint) error
- func (c *Client) SaveImages(opts SaveImageOptions) error
- func (c *Client) StartContainer(id string, hostConfig *HostConfig) error
- func (c *Client) StopContainer(id string, timeout uint) error
- func (c *Client) TagImage(name string, opts TagImageOptions) error
- func (c *Client) Version() (*engine.Env, error)
- func (c *Client) WaitContainer(id string) (int, error)
- type CommitContainerOptions
- type Config
- type Container
- type CopyFromContainerOptions
- type CreateContainerOptions
- type Error
- type Event
- type EventMonitor
- type ExportContainerOptions
- type HandlerFunc
- type HostConfig
- type Image
- type ImagePre012
- type ImportImageOptions
- type KeyValuePair
- type KillContainerOptions
- type ListContainersOptions
- type LogsOptions
- type NetworkSettings
- type NoSuchContainer
- type Port
- type PortBinding
- type PortMapping
- type PullImageOptions
- type PushImageOptions
- type RemoveContainerOptions
- type SaveImageOptions
- type Signal
- type State
- type Subscription
- type TagImageOptions
Examples ¶
Constants ¶
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.
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.
const AllThingsDocker = "*"
AllThingsDocker is a wildcard used to express interest in the Docker lifecycle event streams of all containers and images.
Variables ¶
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") )
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") )
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 ¶
This section is empty.
Types ¶
type APIContainers ¶
type APIContainers struct { ID string `json:"Id"` Image string Command string Created int64 Status string Ports []APIPort SizeRw int64 SizeRootFs int64 Names []string }
APIContainers represents a container.
See http://goo.gl/QeFH7U for more details.
type APIImages ¶
type APIImages struct { ID string `json:"Id"` RepoTags []string `json:",omitempty"` Created int64 Size int64 VirtualSize int64 ParentId string `json:",omitempty"` Repository string `json:",omitempty"` Tag string `json:",omitempty"` }
APIImages represent an image returned in the ListImages call.
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/oPzcqH 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 authencation 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"` InputStream io.Reader `qs:"-"` OutputStream io.Writer `qs:"-"` Remote string `qs:"remote"` }
BuildImageOptions present the set of informations available for building an image from a tarfile with a Dockerfile in it,the details about Dockerfile see http://docs.docker.io/en/latest/reference/builder/
type Change ¶
type Change struct { Path string Kind ChangeType }
Change represents a change in a container.
See http://goo.gl/DpGyzK for more details.
type ChangeType ¶
type ChangeType int
const ( ChangeModify ChangeType = iota ChangeAdd ChangeDelete )
type Client ¶
type Client struct { SkipServerVersionCheck bool // contains filtered or unexported fields }
Client is the basic type of this package. It provides methods for interaction with the API.
func NewClient ¶
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 ¶
NewVersionedClient returns a Client instance ready for communication with the given server endpoint, using a specific remote API version.
func (*Client) AddEventListener ¶
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/oPzcqH 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()) // Attaching to stdout and streaming. 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.
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/628gxm for more details.
func (*Client) ContainerChanges ¶
ContainerChanges returns changes in the filesystem of the given container.
See http://goo.gl/DpGyzK 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/mnxRMl for more details.
Example ¶
client, err := docker.NewClient("http://localhost:4243") if err != nil { log.Fatal(err) } cid := "a84849" // Copy resulting file 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/tjihUc 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/Lqk0FZ 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 ¶
Info returns system-wide information, like the number of running containers.
See http://goo.gl/LOmySw for more details.
func (*Client) InspectContainer ¶
InspectContainer returns information about a container by its ID.
See http://goo.gl/2o52Sx for more details.
func (*Client) InspectImage ¶
InspectImage returns an image by its name or ID.
See http://goo.gl/pHEbma 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/DPbbBy 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/QpCnDN for more details.
func (*Client) ListImages ¶
ListImages returns the list of available images in the server.
See http://goo.gl/dkMrwP for more details.
func (*Client) LoadImages ¶
LoadImages loads tarball with a set of images and tags into docker
See http://goo.gl/Lqk0FZ 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) MonitorEvents ¶
func (c *Client) MonitorEvents() (EventMonitor, error)
MonitorEvents returns an EventMonitor that can be used to listen for and respond to the various events in the Docker container and image lifecycles.
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/PhBKnS 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/GBmyhc 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/PBvGdU for more details.
func (*Client) RemoveEventListener ¶
RemoveEventListener removes a listener from the monitor.
func (*Client) RemoveImage ¶
RemoveImage removes an image by its name or ID.
See http://goo.gl/7hjHHy for more details.
func (*Client) ResizeContainerTTY ¶
ResizeContainerTTY resizes the terminal to the given height and width.
func (*Client) RestartContainer ¶
RestartContainer stops a container, killing it after the given timeout (in seconds), during the stop process.
See http://goo.gl/zms73Z for more details.
func (*Client) SaveImages ¶
func (c *Client) SaveImages(opts SaveImageOptions) error
SaveImages gets a tarball containing all images and metadata from the repository specified.
See http://goo.gl/PhBKnS for more details.
func (*Client) StartContainer ¶
func (c *Client) StartContainer(id string, hostConfig *HostConfig) error
StartContainer starts a container, returning an errror in case of failure.
See http://goo.gl/y5GZlE for more details.
func (*Client) StopContainer ¶
StopContainer stops a container, killing it after the given timeout (in seconds).
See http://goo.gl/X2mj8t for more details.
func (*Client) TagImage ¶
func (c *Client) TagImage(name string, opts TagImageOptions) error
TagImage adds a tag to the image 'name'
func (*Client) Version ¶
Version returns version information about the docker server.
See http://goo.gl/IqKNRE for more details.
func (*Client) WaitContainer ¶
WaitContainer blocks until the given container stops, return the exit code of the container status.
See http://goo.gl/gnHJL2 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/628gxm for more details.
type Config ¶
type Config struct { Hostname string Domainname string User string Memory float64 MemorySwap float64 AttachStdin bool AttachStdout bool AttachStderr bool PortSpecs []string ExposedPorts map[Port]struct{} Tty bool OpenStdin bool StdinOnce bool Env []string Cmd []string Dns []string // For Docker API v1.9 and below only Image string Volumes map[string]struct{} VolumesFrom string WorkingDir string Entrypoint []string NetworkDisabled bool }
type Container ¶
type Container struct { ID string Created time.Time Path string Args []string Config *Config State State Image string NetworkSettings *NetworkSettings SysInitPath string ResolvConfPath string HostnamePath string HostsPath string Name string Driver string Volumes map[string]string VolumesRW map[string]bool HostConfig *HostConfig }
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/mnxRMl for more details.
type CreateContainerOptions ¶
CreateContainerOptions specify parameters to the CreateContainer function.
See http://goo.gl/WPPYtB for more details.
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 ExportContainerOptions ¶
ExportContainerOptions is the set of parameters to the ExportContainer method.
See http://goo.gl/Lqk0FZ for more details.
type HandlerFunc ¶
A HandlerFunc is used to receive Docker lifecycle events.
type HostConfig ¶
type Image ¶
type Image 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:"containerconfig,omitempty"` DockerVersion string `json:"dockerversion,omitempty"` Author string `json:"author,omitempty"` Config *Config `json:"config,omitempty"` Architecture string `json:"architecture,omitempty"` Size int64 }
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 }
type ImportImageOptions ¶
type ImportImageOptions struct { Repository string `qs:"repo"` Tag string `qs:"tag"` Source string `qs:"fromSrc"` 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 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.
type ListContainersOptions ¶
ListContainersOptions specify parameters to the ListContainers function.
See http://goo.gl/QpCnDN for more details.
type LogsOptions ¶
type LogsOptions struct { Container string `qs:"-"` OutputStream io.Writer `qs:"-"` Follow bool Stdout bool Stderr bool Timestamps bool }
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 IPPrefixLen int Gateway string Bridge string PortMapping map[string]PortMapping Ports map[Port][]PortBinding }
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 Port ¶
type Port string
Port represents the port number and the protocol, in the form <number>/<protocol>. For example: 80/tcp.
type PortBinding ¶
type PortMapping ¶
type PullImageOptions ¶
type PullImageOptions struct { Repository string `qs:"fromImage"` Registry string Tag string `qs:"tag"` OutputStream io.Writer `qs:"-"` }
PullImageOptions present the set of options available for pulling an image from a registry.
See http://goo.gl/PhBKnS for more details.
type PushImageOptions ¶
type PushImageOptions struct { // Name of the image Name string // Registry server to push the image Registry string Tag string `qs:"tag"` OutputStream io.Writer `qs:"-"` }
PushImageOptions represents options to use in the PushImage method.
See http://goo.gl/GBmyhc 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.
type SaveImageOptions ¶
SaveImageOptions is the set of parameters to the SaveImages method.
See http://goo.gl/Lqk0FZ for more details.
type Signal ¶
type Signal int
Signal represents a signal that can be send to the container on KillContainer call.
type State ¶
type State struct { sync.RWMutex Running bool Pid int ExitCode int StartedAt time.Time FinishedAt time.Time Ghost bool }
State represents the state of a container.
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.
type TagImageOptions ¶
type TagImageOptions struct { Repo string `qs:"repo"` Force bool `qs:"force"` Tag string `qs:"tag"` }
TagImageOptions present the set of options to tag an image