Documentation
¶
Overview ¶
Package docker is a thin wrapper over the Docker Engine API client that exposes only the operations shed needs.
Index ¶
- func IsConflict(err error) bool
- func IsNotFound(err error) bool
- type Client
- func (c *Client) Close() error
- func (c *Client) CopyFrom(ctx context.Context, id, path string) (io.ReadCloser, error)
- func (c *Client) CopyTo(ctx context.Context, id, dir string, r io.Reader) error
- func (c *Client) Create(ctx context.Context, spec RunSpec) (string, error)
- func (c *Client) CreateIsolated(ctx context.Context, id, name string, labels map[string]string) (string, error)
- func (c *Client) DisconnectNetwork(ctx context.Context, name, id string) error
- func (c *Client) EnsureNetwork(ctx context.Context, name string) error
- func (c *Client) EnsureVolume(ctx context.Context, name string) error
- func (c *Client) Exec(ctx context.Context, id string, cmd []string, stdin io.Reader, ...) error
- func (c *Client) ExposedPorts(ctx context.Context, ref string) ([]int, error)
- func (c *Client) Inspect(ctx context.Context, id string) (Container, error)
- func (c *Client) List(ctx context.Context, labels map[string]string) ([]Container, error)
- func (c *Client) ListImages(ctx context.Context, repo string) ([]Image, error)
- func (c *Client) Logs(ctx context.Context, id string, tail int, follow bool, w io.Writer) error
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) PullImage(ctx context.Context, ref string, w io.Writer) error
- func (c *Client) ReconnectNetwork(ctx context.Context, name, id string, aliases []string) error
- func (c *Client) Remove(ctx context.Context, id string) error
- func (c *Client) RemoveImage(ctx context.Context, ref string) error
- func (c *Client) RemoveNetwork(ctx context.Context, name string) error
- func (c *Client) RemoveVolume(ctx context.Context, name string) error
- func (c *Client) ResolveImage(ctx context.Context, ref string) (string, error)
- func (c *Client) Restart(ctx context.Context, id string, timeout time.Duration) error
- func (c *Client) Run(ctx context.Context, spec RunSpec) (string, error)
- func (c *Client) Start(ctx context.Context, id string) error
- func (c *Client) Stats(ctx context.Context, id string) (Stats, error)
- func (c *Client) Stop(ctx context.Context, id string, timeout time.Duration) error
- func (c *Client) VolumeExists(ctx context.Context, name string) (bool, error)
- type Container
- type ExitError
- type Image
- type Mount
- type PortBinding
- type RunSpec
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsConflict ¶
IsConflict reports whether err means that an object is still in use.
func IsNotFound ¶
IsNotFound reports whether err means that a Docker object does not exist.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to a Docker Engine.
func New ¶
New returns a Client configured from the standard DOCKER_* environment variables. The API version is negotiated with the daemon on first use.
func (*Client) CopyFrom ¶
CopyFrom returns a tar stream of path in container id, using the Docker archive API. It works on created and stopped containers. The caller closes the stream.
func (*Client) CopyTo ¶
CopyTo extracts the tar stream r into the directory dir of container id. The directory must exist.
func (*Client) Create ¶
Create creates a container from spec without starting it and returns its ID. An empty spec.Network leaves the container with no networking configuration, so it uses the daemon's default network if it is ever started.
func (*Client) CreateIsolated ¶
func (c *Client) CreateIsolated(ctx context.Context, id, name string, labels map[string]string) (string, error)
CreateIsolated creates a stopped copy of the container id, named name and labeled with labels instead of the original's labels, and returns its ID. The copy runs the same image, entrypoint, command, environment, user, and mounts, with the same resource limits. It has no network but loopback and publishes no ports, so nothing outside it can connect to it, and Docker never restarts it, not even when the daemon starts again. Anonymous volumes of the original are not shared: the copy gets its own.
func (*Client) DisconnectNetwork ¶
DisconnectNetwork disconnects the container id from the network name, which also drops its DNS aliases there.
func (*Client) EnsureNetwork ¶
EnsureNetwork creates the bridge network name if it does not exist.
func (*Client) EnsureVolume ¶
EnsureVolume creates the named volume if it does not exist.
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, id string, cmd []string, stdin io.Reader, stdout, stderr io.Writer) error
Exec runs cmd in the running container id. stdin may be nil. stdout and stderr receive the command's output separately. Output is streamed, never buffered in memory. It returns an *ExitError when the command exits non-zero.
stdin is copied in full and then closed, so the command sees EOF. If reading stdin fails, the connection is aborted rather than closed cleanly, so the command cannot mistake truncated input for complete input, and Exec returns the read error. Exec does not return until the copy of stdin has finished, so a Read on stdin must not block forever once the command is gone.
Canceling ctx aborts the stream and returns ctx's error. The command itself may keep running in the container.
func (*Client) ExposedPorts ¶
ExposedPorts returns the TCP ports that the image ref declares as exposed, in ascending order.
func (*Client) List ¶
List returns all containers, stopped ones included, that have every one of the given labels. An empty label value matches any value.
func (*Client) ListImages ¶
ListImages returns the local images tagged in repository repo, one entry per tag.
func (*Client) Logs ¶
Logs copies the container's stdout and stderr to w, each line prefixed with its RFC 3339 timestamp and a space. A negative tail means all lines. With follow, Logs blocks until ctx is done or the container exits; canceling ctx is not an error.
func (*Client) ReconnectNetwork ¶
ReconnectNetwork replaces the DNS aliases, besides its name, of the container id on the network name, to which it must be connected. Docker cannot change the aliases of a connected container, so it is disconnected and connected again, asking for the addresses it had so that they do not change.
func (*Client) Remove ¶
Remove force-removes the container and its anonymous volumes, such as those Docker creates for the VOLUME paths of its image. Named volumes (like shed-vol-*) are never removed by RemoveVolumes: Docker deletes only the volumes it generated names for, like docker rm -v. A missing container is not an error.
func (*Client) RemoveImage ¶
RemoveImage removes the image ref. A missing image is not an error.
func (*Client) RemoveNetwork ¶
RemoveNetwork removes the network name. A missing network is not an error.
func (*Client) RemoveVolume ¶
RemoveVolume removes the named volume. A missing volume is not an error.
func (*Client) ResolveImage ¶
ResolveImage returns the immutable local ID of the image referenced by ref.
func (*Client) Restart ¶
Restart stops the container, killing it if it has not exited within timeout, and starts it again.
func (*Client) Run ¶
Run creates and starts a container and returns its ID. The container is restarted unless explicitly stopped.
A failed start can be ambiguous: Docker may have started the container although the request failed, for example when the connection dropped. Run then removes the container. If that removal fails too, Run returns the container's ID along with the error, since the container may be running.
type Container ¶
type Container struct {
ID string
Name string
Image string
State string // created, running, paused, restarting, removing, exited or dead
Running bool
// ExitCode is the exit code of the last run.
ExitCode int
// IPs maps network name to the container's IP address on it.
IPs map[string]string
Labels map[string]string
// Volumes lists the named volumes mounted into the container.
Volumes []string
// CPULimit is the configured CPU limit in cores; zero means unlimited.
// Only Inspect sets it.
CPULimit float64
// MemoryLimit is the configured memory limit in bytes; zero means
// unlimited. Only Inspect sets it.
MemoryLimit int64
}
Container is the observed state of a container.
type ExitError ¶
type ExitError struct {
Code int
}
ExitError reports that a command run by Exec exited with a non-zero status.
type PortBinding ¶
type PortBinding struct {
HostPort, ContainerPort int
}
PortBinding publishes a container TCP port on all host interfaces.
type RunSpec ¶
type RunSpec struct {
Name string
Image string
Cmd []string // nil means the image default
Env []string // KEY=VALUE
Labels map[string]string
Network string
Aliases []string // DNS names on Network
Mounts []Mount
Publish []PortBinding
// CPUs is the CPU quota in cores and Memory the memory limit in bytes,
// with no extra swap. Zero means unlimited.
CPUs float64
Memory int64
}
RunSpec describes a container to create, and usually to start.
type Stats ¶
type Stats struct {
Read time.Time
// CPUTotal is the CPU time the container has used, in nanoseconds.
CPUTotal uint64
// SystemCPU is the CPU time the host has used across all CPUs, in
// nanoseconds; zero if the daemon does not report it.
SystemCPU uint64
OnlineCPUs uint32
// MemoryUsage is the memory in use in bytes, excluding inactive page
// cache.
MemoryUsage uint64
// NetRx and NetTx are bytes received and sent, summed over all
// interfaces.
NetRx, NetTx uint64
// DiskRead and DiskWrite are block device bytes read and written.
DiskRead, DiskWrite uint64
}
Stats is a point-in-time sample of a container's resource usage. Counters are cumulative since the container started; rates come from the difference between two samples.