c8dockerclient

package
v0.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package c8dockerclient is a homegrown HTTP Docker API client. It is primarily used with the Docker unix socket /var/run/docker.sock to retrieve information about running containers when using the Docker container engine.

Index

Constants

View Source
const (
	DIFF_MODIFIED uint8 = 0
	DIFF_ADDED    uint8 = 1
	DIFF_DELETED  uint8 = 2
)
View Source
const ApiPrefix = "/v1.24"

DockerSocketPath is the filesytem path to the docker socket

View Source
const DockerSocketPath = "/var/run/docker.sock"
View Source
const (
	MOUNT_TYPE_BIND = "bind"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	SocketPath string
}

Client serves as the main structure for dealing with the docker socket

func NewClient

func NewClient() (cli *Client)

NewClient creates a new C8DockerClient instance tied to local docker socket.

func (*Client) ContainerDiff

func (client *Client) ContainerDiff(containerID string) (fileList []DockerFileChange,
	err error)

ContainerDiff diffs the file system from when the container was started to when the function was called

func (*Client) ContainerTop

func (client *Client) ContainerTop(containerID string) ([]*ProcessEntry, error)

ContainerTop gets the processes in the container specified by id. This is primarily used to list the processes in running containers that may have started before our instrumentation.

func (*Client) DockerInfo

func (client *Client) DockerInfo() (*DockerInfo, error)

DockerInfo gets the docker engine version, OS and more.

func (*Client) EventChannel

func (client *Client) EventChannel() (chan DockerEventMessage, chan interface{}, error)

EventChannel connects to the Docker socket and executes the docker events command, this returns a channel for receiving those events, and an error

func (*Client) InspectContainer

func (client *Client) InspectContainer(containerID string) (*DockerContainerInfo, error)

InspectContainer gets all of the information the docker engine has on a container via it's /inspect URI

func (*Client) InspectImage

func (client *Client) InspectImage(imageID string) (*DockerImageInfo, error)

InspectImage retrieves all information about an image for the given imageID

func (*Client) InspectNetwork

func (client *Client) InspectNetwork(networkID string) (*DockerNetworkInfo, error)

InspectNetwork gets all network information

func (*Client) KillContainer

func (client *Client) KillContainer(containerID, signal string) (err error)

KillContainer terminates the container process by sending the signal but does not remove the container from the docker host.

func (*Client) ListContainers

func (client *Client) ListContainers() ([]DockerContainerListInfo, error)

ListContainers lists all of the running containers.

func (*Client) Request

func (client *Client) Request(path, method string, values *url.Values) (resp *http.Response, err error)

Request makes an HTTP request

func (*Client) RestartContainer

func (client *Client) RestartContainer(containerID string) (err error)

RestartContainer restarts the container with the given containerID.

type ClientError

type ClientError struct {
	// contains filtered or unexported fields
}

ClientError encapsulates all errors

func (*ClientError) Error

func (c *ClientError) Error() string

Return the error

type DockerContainerInfo

type DockerContainerInfo struct {
	Name            string                         `json:"Name"`
	Path            string                         `json:"Path"`
	Arguments       []string                       `json:"Args"`
	ContainerID     string                         `json:"Id"`
	ImageID         string                         `json:"Image"`
	State           DockerContainerState           `json:"State"`
	NetworkSettings DockerContainerNetworkSettings `json:"NetworkSettings"`
	Mounts          []DockerVolumeMounts           `json:"Mounts"`
}

DockerContainerInfo represents the result of inspecting a docker container.

func (*DockerContainerInfo) String

func (info *DockerContainerInfo) String() string

type DockerContainerListInfo

type DockerContainerListInfo struct {
	//The only field we need is ContainerID, we then Inspect it to
	//get DockerContainerInfo
	ContainerID string `json:"ID"`
}

DockerContainerListInfo lists the ContainerID. The information returned by ContainerList (/containers/json) This type is used in container-enumeration at daemon start-up

func (*DockerContainerListInfo) String

func (container *DockerContainerListInfo) String() string

type DockerContainerNetworkSettings

type DockerContainerNetworkSettings struct {
	// This IP might NOT be what we want
	// there is also an IP in each DockerNetwork entry in Networks map
	IPAddress   string                         `json:"IPAddress"`
	IPPrefixLen uint32                         `json:"IPPrefixLen"`
	Ports       map[string][]DockerPortForward `json:"Ports"`
	Networks    map[string]DockerNetwork       `json:"Networks"` //maps network type to network ID
}

DockerContainerNetworkSettings holds the network configuration information for a running Docker container. This is a substructure of DockerContainerInfo

func (*DockerContainerNetworkSettings) String

func (settings *DockerContainerNetworkSettings) String() string

type DockerContainerProcessList

type DockerContainerProcessList struct {
	Processes [][]string `json:"Processes"`
	Titles    []string   `json:"Titles"`
}

DockerContainerProcessList is a helper struct for parsing the json from Docker's Top command

func (*DockerContainerProcessList) String

func (processList *DockerContainerProcessList) String() string

type DockerContainerState

type DockerContainerState struct {
	StartTime time.Time `json:"StartedAt"`
	//PIDs in linux are limited to 4,000,000
	//see http://lxr.free-electrons.com/source/include/linux/threads.h#L33
	ProcessID uint64 `json:"Pid"`
}

DockerContainerState represents when the container was started and its ProcessID. This is a sub-structure of DockerContainerInfo

type DockerEventActor

type DockerEventActor struct {
	ID         string            `json:"ID"`
	Attributes map[string]string `json:"Attributes"`
}

DockerEventActor represents the container or image that a Docker Event affects

func (*DockerEventActor) String

func (actor *DockerEventActor) String() string

type DockerEventMessage

type DockerEventMessage struct {
	Status   string `json:"status,omitempty"`
	ID       string `json:"id,omitempty"`
	From     string `json:"from,omitempty"`
	Type     string `json:"Type"`
	Action   string `json:"Action"`
	Actor    DockerEventActor
	Time     int64 `json:"time,omitempty"` //docker uses unix timestamps for these
	TimeNano int64 `json:"timeNano,omitempty"`
}

DockerEventMessage encapsulates all information about a Docker event.

func (*DockerEventMessage) String

func (event *DockerEventMessage) String() string

type DockerFileChange

type DockerFileChange struct {
	Kind uint8  `json:"kind"`
	Path string `json:"path"`
}

DockerFileChange is the json object returned by docker diff

type DockerImageInfo

type DockerImageInfo struct {
	ImageID  string       `json:"ID"`
	ParentID string       `json:"Parent"`
	RepoTags []string     `json:"RepoTags"`
	Layers   RootFSLayers `json:"RootFS"`
}

DockerImageInfo represents the JSON object returned by ImageInspect (/images/<imageID>/json). The only field currently of interest at time of writing is RepoTags TODO: add layer information here

func (*DockerImageInfo) String

func (imageInfo *DockerImageInfo) String() string

type DockerInfo

type DockerInfo struct {
	DockerID          string `json:"ID"`
	DockerVersion     string `json:"ServerVersion"`
	KernelVersion     string `json:"KernelVersion"`
	OS                string `json:"OperatingSystem"`
	OSType            string `json:"OSType"`
	Hostname          string `json:"Name"`
	Architecture      string `json:"Architecture"`
	ContainersRunning int    `json:"ContainersRunning"`
}

DockerInfo represents the information extracted from a docker info command.

func (*DockerInfo) String

func (info *DockerInfo) String() string

type DockerNetwork

type DockerNetwork struct {
	NetworkID string `json:"NetworkID"`
	IPAddress string `json:"IPAddress"`
}

DockerNetwork represents a docker network that a container is attached to. This is a substructure of DockerContainerNetwork settings

func (*DockerNetwork) String

func (network *DockerNetwork) String() string

type DockerNetworkInfo

type DockerNetworkInfo struct {
	Name    string
	Options map[string]string `json:"Options"`
}

DockerNetworkInfo is returned by NetworkInspect (/networks/<networkdID>)

func (*DockerNetworkInfo) String

func (network *DockerNetworkInfo) String() string

type DockerPortForward

type DockerPortForward struct {
	HostIP   string `json:"HostIp"`
	HostPort string `json:"HostPort"`
}

DockerPortForward contains the container's host's forwarded IP and ports e.g. port 2222 on an external IP of a host is actually passed to that container

type DockerVolumeMounts

type DockerVolumeMounts struct {
	Type        string `json:"Type"`        // this is the type of volume (bind)
	Source      string `json:"Source"`      // this is the file path in the container host
	Destination string `json:"Destination"` // this is the file path inside the container
	ReadWrite   bool   `json:"RW"`          // is this mounted readwrite (true = yes)
	Mode        string `json:"Mode"`        // the mode the volume uses
	Propagation string `json:"Propagation"` // this lets us know if the volume changes get

}

DockerVolumeMounts represents the metadata associated.

type ProcessEntry

type ProcessEntry struct {
	User            string `json:"user"`
	Command         string `json:"command"`
	ProcessID       uint64 `json:"pid"`
	ParentProcessID uint64 `json:"ppid"`
	CGroup          uint64 `json:"cgroup"`
}

ProcessEntry represents a node in a process tree as found from docker top

func (*ProcessEntry) String

func (process *ProcessEntry) String() string

type RootFSLayers

type RootFSLayers struct {
	Type   string   `json:"Type"`
	Layers []string `json:"Layers"`
}

RootFSLayers represents the RootFS json object found when inspecting an image. This represents all of the Image SHA1s that comprise the layers of this image.

Directories

Path Synopsis
tests

Jump to

Keyboard shortcuts

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