Documentation
¶
Overview ¶
Package docker is a minimal Docker Engine API client over a unix socket, built on the standard library only.
Index ¶
- Variables
- type APIError
- type Client
- func (c *Client) Attach(ctx context.Context, id string) (io.ReadWriteCloser, error)
- func (c *Client) BridgeGateway(ctx context.Context) (string, error)
- func (c *Client) CreateContainer(ctx context.Context, name string, cfg ContainerConfig) (string, error)
- func (c *Client) EnsureImage(ctx context.Context, ref string, progress func(string)) error
- func (c *Client) ImageExists(ctx context.Context, ref string) (bool, error)
- func (c *Client) InspectContainer(ctx context.Context, id string) (ContainerState, error)
- func (c *Client) KillContainer(ctx context.Context, id, signal string) error
- func (c *Client) Logs(ctx context.Context, id string, tail int) (string, error)
- func (c *Client) Ping(ctx context.Context) (string, error)
- func (c *Client) PullImage(ctx context.Context, ref string, progress func(string)) error
- func (c *Client) RemoveContainer(ctx context.Context, id string) error
- func (c *Client) StartContainer(ctx context.Context, id string) error
- func (c *Client) Stats(ctx context.Context, id string) (StatsSample, error)
- func (c *Client) Version(ctx context.Context) (string, error)
- func (c *Client) WaitContainer(ctx context.Context, id string) (int, error)
- type ContainerConfig
- type ContainerState
- type HostConfig
- type LogConfig
- type PortBinding
- type StatsSample
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("docker: not found")
ErrNotFound is returned for missing containers or images.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Docker Engine API.
func (*Client) Attach ¶
Attach connects to a TTY container's stdin/stdout. Reads return the raw output stream; writes go to the process's stdin. Close the connection to detach.
func (*Client) BridgeGateway ¶
BridgeGateway returns the gateway IP of Docker's default bridge network (usually 172.17.0.1), which containers use to reach services on the host ({{config.docker.interface}} in eggs).
func (*Client) CreateContainer ¶
func (c *Client) CreateContainer(ctx context.Context, name string, cfg ContainerConfig) (string, error)
CreateContainer creates a container and returns its ID.
func (*Client) EnsureImage ¶
EnsureImage pulls ref unless it is already present.
func (*Client) ImageExists ¶
ImageExists reports whether an image is present locally.
func (*Client) InspectContainer ¶
InspectContainer returns a container's state; ErrNotFound if it does not exist.
func (*Client) KillContainer ¶
KillContainer sends a signal (e.g. "SIGKILL", "SIGINT") to the container's main process.
func (*Client) PullImage ¶
PullImage downloads an image. Progress lines are passed to progress (may be nil).
func (*Client) RemoveContainer ¶
RemoveContainer force-removes a container (and anonymous volumes). Missing containers are not an error.
func (*Client) StartContainer ¶
StartContainer starts a created container.
func (*Client) Stats ¶
Stats takes a single resource sample without waiting for a second one (one-shot). CPU percentage needs two samples; the caller keeps the previous one.
type ContainerConfig ¶
type ContainerConfig struct {
Image string `json:"Image"`
Cmd []string `json:"Cmd,omitempty"`
Entrypoint []string `json:"Entrypoint,omitempty"`
Env []string `json:"Env,omitempty"`
User string `json:"User,omitempty"`
WorkingDir string `json:"WorkingDir,omitempty"`
Tty bool `json:"Tty"`
OpenStdin bool `json:"OpenStdin"`
StdinOnce bool `json:"StdinOnce"`
AttachStdin bool `json:"AttachStdin"`
AttachStdout bool `json:"AttachStdout"`
AttachStderr bool `json:"AttachStderr"`
Labels map[string]string `json:"Labels,omitempty"`
ExposedPorts map[string]struct{} `json:"ExposedPorts,omitempty"`
HostConfig HostConfig `json:"HostConfig"`
}
ContainerConfig is the subset of the engine's create body the agent uses.
type ContainerState ¶
type ContainerState struct {
Running bool `json:"Running"`
ExitCode int `json:"ExitCode"`
Status string `json:"Status"`
OOMKill bool `json:"OOMKilled"`
}
ContainerState is the part of inspect the agent needs.
type HostConfig ¶
type HostConfig struct {
Binds []string `json:"Binds,omitempty"`
PortBindings map[string][]PortBinding `json:"PortBindings,omitempty"`
Memory int64 `json:"Memory,omitempty"`
MemorySwap int64 `json:"MemorySwap,omitempty"`
NanoCPUs int64 `json:"NanoCpus,omitempty"`
PidsLimit int64 `json:"PidsLimit,omitempty"`
CapDrop []string `json:"CapDrop,omitempty"`
SecurityOpt []string `json:"SecurityOpt,omitempty"`
Tmpfs map[string]string `json:"Tmpfs,omitempty"`
ReadonlyRootfs bool `json:"ReadonlyRootfs"`
Init *bool `json:"Init,omitempty"`
LogConfig *LogConfig `json:"LogConfig,omitempty"`
}
HostConfig holds limits, mounts and ports.
type LogConfig ¶
type LogConfig struct {
Type string `json:"Type"`
Config map[string]string `json:"Config,omitempty"`
}
LogConfig selects the container log driver.
type PortBinding ¶
PortBinding maps a container port to a host IP:port.
type StatsSample ¶
type StatsSample struct {
CPUTotal uint64 // container CPU time, ns
SystemTotal uint64 // host CPU time, ns
OnlineCPUs int
MemoryUsed uint64 // usage minus page cache, like `docker stats`
MemoryLimit uint64
NetRx uint64
NetTx uint64
}
StatsSample is one reading of a container's resource usage.