dock

package
v0.0.0-...-c9163c1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: AGPL-3.0 Imports: 22 Imported by: 11

Documentation

Index

Constants

View Source
const (
	NotRunning = "not-running" // Wait till a container finishes running.
	NextExit   = "next-exit"   // Wait till the next exit event.
	Removed    = "removed"     // Wait till a container is removed.
)

Container events to wait for.

View Source
const (
	MountBind      = "bind"
	MountVolume    = "volume"
	MountTemp      = "tmpfs"
	MountNamedPipe = "npipe"
)

Mount types.

View Source
const Socket = "/var/run/docker.sock"

Socket is the default socket location.

Variables

This section is empty.

Functions

func AddDockerfileToStream

func AddDockerfileToStream(s *tarutil.Stream, content string)

AddDockerfileToStream adds a DockerFile of content with mode 0600.

func BuildImage

func BuildImage(c *Client, tag string, tarball io.Reader) error

BuildImage builds a docker image using the given tarball stream, and assigns the given tag.

func BuildImageConfig

func BuildImageConfig(c *Client, tag string, config *BuildConfig) error

BuildImageConfig builds the image with the given config.

func BuildImageStream

func BuildImageStream(c *Client, tag string, files *tarutil.Stream) error

BuildImageStream builds a docker image using the given tarball stream, and assigns the given tag.

func CopyInTarFile

func CopyInTarFile(c *Cont, file, toPath string) error

CopyInTarFile copies a tar file into the container.

func CopyInTarGz

func CopyInTarGz(c *Cont, f, target string) error

CopyInTarGz copies a gzipped tarball into the container.

func CopyInTarStream

func CopyInTarStream(c *Cont, files *tarutil.Stream, target string) error

CopyInTarStream copies in a tarutil.Stream into the container.

func CopyOutTarFile

func CopyOutTarFile(c *Cont, fromPath, file string) error

CopyOutTarFile copies a file or a directory out of the container into a tarball file.

func CopyOutTarGz

func CopyOutTarGz(c *Cont, target, f string) error

CopyOutTarGz copies out a directory of file into a gzipped tarball.

func CreateNetwork

func CreateNetwork(c *Client, name string) error

CreateNetwork creates a network with the given name.

func CreateVolume

func CreateVolume(
	c *Client, name string, config *VolumeConfig,
) (string, error)

CreateVolume creates a new volume

func CreateVolumeIfNotExist

func CreateVolumeIfNotExist(
	c *Client, name string, config *VolumeConfig,
) (string, error)

CreateVolumeIfNotExist creates the volume if the volume of the given name does not exist.

func HasCont

func HasCont(c *Client, name string) (bool, error)

HasCont checks if a container exists.

func HasImage

func HasImage(c *Client, name string) (bool, error)

HasImage checks if a particular image exists.

func HasNetwork

func HasNetwork(c *Client, name string) (bool, error)

HasNetwork checks if a network exists.

func LoadImages

func LoadImages(c *Client, r io.Reader) error

LoadImages loads a tarball stream into Docker repository.

func LoadImagesFromFile

func LoadImagesFromFile(c *Client, f string) error

LoadImagesFromFile loads a tarball file into Docker repository.

func NewTarStream

func NewTarStream(dockerfile string) *tarutil.Stream

NewTarStream creates a stream with a docker file.

func ParseImageTag

func ParseImageTag(s string) (image, tag string)

ParseImageTag parses "image:tag" into ("image", "tag").

func PruneImages

func PruneImages(c *Client, opt *PruneImagesOption) error

PruneImages prunes the unused images.

func PullImage

func PullImage(c *Client, image, tag string) error

PullImage pulls the specified image and save it as the related tag.

func ReadContFile

func ReadContFile(c *Cont, f string) ([]byte, error)

ReadContFile reads out a single file from a container.

func RemoveImage

func RemoveImage(c *Client, name string, opts *RemoveImageOptions) error

RemoveImage removes a local docker image.

func RemoveNetwork

func RemoveNetwork(c *Client, name string) error

RemoveNetwork removes a network of the given name.

func RemoveVolume

func RemoveVolume(c *Client, name string) error

RemoveVolume deletes a volume.

func RenameCont

func RenameCont(client *Client, from, to string) error

RenameCont renames an existing container.

func RunTask

func RunTask(c *Cont, line string) error

RunTask runs a command line.

func RunTasks

func RunTasks(c *Cont, lines []string) error

RunTasks runs a series of command lines. All commands must succeed and return 0 exit value.

func SaveImageGz

func SaveImageGz(c *Client, name, file string) error

SaveImageGz saves a single image to a gzipped tarball file.

func SaveImages

func SaveImages(c *Client, names []string, w io.Writer) error

SaveImages saves built images as a tarball stream into the writer.

func SaveImagesGz

func SaveImagesGz(c *Client, names []string, f string) error

SaveImagesGz saves images to a gzipped tarball file.

func TagImage

func TagImage(c *Client, name, repo, tag string) error

TagImage tags an image.

Types

type BuildConfig

type BuildConfig struct {
	Tarball  io.Reader
	Files    *tarutil.Stream
	Args     map[string]string
	UseCache bool
}

BuildConfig is the configuration for building an image.

type Client

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

Client is a docker daemon client that can be used to issue docker commands.

func NewClient

func NewClient(c *httputil.Client) *Client

NewClient creates a new client using the given httputil.Client

func NewUnixClient

func NewUnixClient(sock string) *Client

NewUnixClient creates a new unix domain socket client. When sock is empty, "/var/run/docker.sock" is used.

type Cont

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

Cont wraps a container.

func CreateCont

func CreateCont(c *Client, image string, config *ContConfig) (*Cont, error)

CreateCont creates a new container with the given config.

func NewCont

func NewCont(c *Client, id string) *Cont

NewCont creates a new container handle by ID or name.

func (*Cont) CopyInTar

func (c *Cont) CopyInTar(r io.Reader, to string) error

CopyInTar copies a tar stream into the container.

func (*Cont) CopyOut

func (c *Cont) CopyOut(src, destDir string) error

CopyOut copies a file or a directory into the destination.

func (*Cont) CopyOutFile

func (c *Cont) CopyOutFile(src, dest string) error

CopyOutFile copies a single file into the destination.

func (*Cont) CopyOutTar

func (c *Cont) CopyOutTar(fromPath string, w io.Writer) error

CopyOutTar copies a file or a directory out of the container into a tarball stream.

func (*Cont) Drop

func (c *Cont) Drop() error

Drop stops and removes the container.

func (*Cont) Exec

func (c *Cont) Exec(line string) (int, error)

Exec executes a command line. Returns the exit value or any error.

func (*Cont) ExecArgs

func (c *Cont) ExecArgs(args []string) (int, error)

ExecArgs executes a command with the given args. Returns the exit value or any error.

func (*Cont) ExecWithSetup

func (c *Cont) ExecWithSetup(s *ExecSetup) (int, error)

ExecWithSetup executes a command with the given setup.

func (*Cont) Exists

func (c *Cont) Exists() (bool, error)

Exists checks if the container exists.

func (*Cont) FollowLogs

func (c *Cont) FollowLogs(out io.Writer) error

FollowLogs follows the container's logs and forwards it into the writer.

func (*Cont) ForceRemove

func (c *Cont) ForceRemove() error

ForceRemove force removes the container.

func (*Cont) ID

func (c *Cont) ID() string

ID returns the container's ID.

func (*Cont) Inspect

func (c *Cont) Inspect() (*ContInfo, error)

Inspect inspects the container.

func (*Cont) Remove

func (c *Cont) Remove() error

Remove removes the container.

func (*Cont) SendSIGINT

func (c *Cont) SendSIGINT() error

SendSIGINT sends SIGINT (Ctrl-C) to the container.

func (*Cont) Start

func (c *Cont) Start() error

Start starts the container.

func (*Cont) Stop

func (c *Cont) Stop() error

Stop stops the container.

func (*Cont) Wait

func (c *Cont) Wait(cond string) (int, error)

Wait for container to finish running.

type ContConfig

type ContConfig struct {
	Name          string
	Hostname      string
	Mounts        []*ContMount
	Devices       []*ContDevice
	TCPBinds      []*PortBind
	UDPBinds      []*PortBind
	Env           map[string]string
	Network       string
	Privileged    bool
	AlwaysRestart bool // Use restart policy "always".
	AutoRestart   bool // Use restart policy "unless-stopped".
	Cmd           []string
	WorkDir       string
	Labels        map[string]string

	JSONLogConfig *JSONLogConfig
}

ContConfig contains the configuration for creating a container.

type ContDevice

type ContDevice struct {
	Host        string
	Cont        string
	CgroupPerms string
}

ContDevice specifies devices to map into the container.

type ContInfo

type ContInfo struct {
	ID     string `json:"Id"`
	Image  string
	Config struct {
		Image    string
		Hostname string
		Labels   map[string]string
	}
	State struct {
		ExitCode int
		Error    string
		Running  bool
	}
	HostConfig struct {
		Mounts []*ContMountInfo
	}
}

ContInfo is the inspection result of a container.

func InspectCont

func InspectCont(c *Client, name string) (*ContInfo, error)

InspectCont inspects the state of a container.

type ContListInfo

type ContListInfo struct {
	ID      string `json:"Id"`
	Names   []string
	Image   string
	ImageID string
	Labels  map[string]string
}

ContListInfo is the container info got from listing.

func ListContsWithLabel

func ListContsWithLabel(c *Client, label string) ([]*ContListInfo, error)

ListContsWithLabel lists all containers with the given label.

type ContMount

type ContMount struct {
	Host     string
	Cont     string
	ReadOnly bool
	Type     string // Default: "bind"
}

ContMount specifies a containter bind option.

func (*ContMount) String

func (b *ContMount) String() string

type ContMountInfo

type ContMountInfo struct {
	Type        string
	Target      string
	Source      string
	ReadOnly    bool   `json:",omitempty"`
	Consistency string `json:",omitempty"`
}

ContMountInfo is the information of a mount in the container.

type ExecSetup

type ExecSetup struct {
	Cmd        []string
	Env        []string `json:",omitempty"`
	User       string   `json:",omitempty"`
	WorkingDir string   `json:",omitempty"`

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

ExecSetup contains the setup arguments to run a command inside a running container.

type GoBuild

type GoBuild struct {
	Git     string
	RepoPkg string
	Pkg     string
	Bin     string
	SSHTar  string
}

GoBuild is a golang build.

func ShanhuBuild

func ShanhuBuild(name, sshTar string) *GoBuild

ShanhuBuild returns the golang build for shanhu releases.

func (*GoBuild) Run

func (b *GoBuild) Run(client *Client) error

Run runs a Go language build job.

type ImageInfo

type ImageInfo struct {
	ID          string `json:"Id,omitempty"`
	Parent      string
	VirtualSize int64
	RepoTags    []string `json:",omitempty"`
	RepoDigests []string `json:",omitempty"`
}

ImageInfo is the inspection result of an image.

func InspectImage

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

InspectImage inspects a particular image.

type ImageListInfo

type ImageListInfo struct {
	ID       string `json:"Id,omitempty"`
	RepoTags []string
	Labels   map[string]string
}

ImageListInfo is the information of an image listing.

func ListImages

func ListImages(c *Client) ([]*ImageListInfo, error)

ListImages lists all images

type JSONLogConfig

type JSONLogConfig struct {
	MaxSize string
	MaxFile int
}

JSONLogConfig contains the logging option for a docker.

func LimitedJSONLog

func LimitedJSONLog() *JSONLogConfig

LimitedJSONLog returns a log config that has max-size=10 and max-file=3 as json-file logging options.

type NetworkIPAM

type NetworkIPAM struct {
	Config []*NetworkIPAMConfig `json:",omitempty"`
}

NetworkIPAM is the configuration section of IP address management.

type NetworkIPAMConfig

type NetworkIPAMConfig struct {
	Subnet  string
	Gateway string
}

NetworkIPAMConfig is the IP address management config entry.

type NetworkInfo

type NetworkInfo struct {
	Name   string
	ID     string `json:"Id"`
	Driver string
	IPAM   *NetworkIPAM `json:",omitempty"`
}

NetworkInfo contains information of a docker network.

func InspectNetwork

func InspectNetwork(c *Client, name string) (*NetworkInfo, error)

InspectNetwork inspects a network.

type PortBind

type PortBind struct {
	ContPort int
	HostIP   string
	HostPort int
}

PortBind specifies a coutainer port bind option.

type PruneImagesOption

type PruneImagesOption struct {
	Unused bool
}

PruneImagesOption provides options for unused image pruning.

type RemoveImageOptions

type RemoveImageOptions struct {
	Force   bool // Force remove the image
	NoPrune bool // NoPrune keeps un-tagged images after removal
}

RemoveImageOptions defines options when docker images are removed.

type VolumeConfig

type VolumeConfig struct {
	Labels map[string]string
	Driver string
}

VolumeConfig is the configuration of a new volume.

type VolumeInfo

type VolumeInfo struct {
	Name       string
	Driver     string
	Mountpoint string
	Labels     map[string]string
}

VolumeInfo contains the information of a volume

func InspectVolume

func InspectVolume(c *Client, name string) (*VolumeInfo, error)

InspectVolume inspects a volume.

func ListVolumesWithLabel

func ListVolumesWithLabel(c *Client, label string) ([]*VolumeInfo, error)

ListVolumesWithLabel lists all volumes with the specific label.

Jump to

Keyboard shortcuts

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