godock

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomString

func GenerateRandomString(length int) string

func StatsFormatter

func StatsFormatter(writer io.Writer) *formater

Formats the incoming stats and passes it to the supplied writer

Types

type Client

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

func NewClient

func NewClient(ctx context.Context) (*Client, error)

func (*Client) BuildImage

func (c *Client) BuildImage(ctx context.Context, imageConfig *image.ImageConfig) error

func (*Client) ConnectContainerToNetwork

func (c *Client) ConnectContainerToNetwork(ctx context.Context, networkConfig *network.NetworkConfig, containerConfig *container.ContainerConfig) error

func (*Client) ContainerCommit added in v1.0.2

func (c *Client) ContainerCommit(ctx context.Context, containerConfig *container.ContainerConfig, imageConfig *image.ImageConfig, commitOptions ...commitoptions.CommitOptionsFn) (string, error)

ContainerCommit applies changes to a container and creates a new tagged image.

func (*Client) ContainerDiff added in v1.0.2

func (c *Client) ContainerDiff(ctx context.Context, containerConfig *container.ContainerConfig) ([]Diff, error)

ContainerDiff returns the changes on a container's filesystem.

func (*Client) ContainerExecAttach added in v1.0.2

func (c *Client) ContainerExecAttach(ctx context.Context, containerConfig *container.ContainerConfig, execConfig *exec.ExecConfig) (*types.HijackedResponse, error)

ContainerExecAttach attaches to a container exec command and returns a hijacked response that can be used to read the output of the exec command. It is up to the caller to close the hijacked response.

func (*Client) ContainerExecAttachTerminal added in v1.0.2

func (c *Client) ContainerExecAttachTerminal(ctx context.Context, containerConfig *container.ContainerConfig, execConfig *exec.ExecConfig) (*terminal.Session, error)

ContainerExecAttachTerminal attaches to a container exec command and returns a terminal session that can be used to interact with the command. The session handles terminal setup, raw mode, and cleanup automatically.

func (*Client) ContainerExecInspect added in v1.0.2

func (c *Client) ContainerExecInspect(ctx context.Context, containerConfig *container.ContainerConfig, execConfig *exec.ExecConfig) (*ExecInspect, error)

ContainerExecInspect returns information about a container exec command.

func (*Client) ContainerExecResize added in v1.0.2

func (c *Client) ContainerExecResize(ctx context.Context, containerConfig *container.ContainerConfig, execConfig *exec.ExecConfig, height, width uint) error

ContainerExecResize resizes the TTY of a container exec command.

func (*Client) ContainerExecStart added in v1.0.2

func (c *Client) ContainerExecStart(ctx context.Context, containerConfig *container.ContainerConfig, execConfig *exec.ExecConfig) error

func (*Client) ContainerExport added in v1.0.2

func (c *Client) ContainerExport(ctx context.Context, containerConfig *container.ContainerConfig) (io.ReadCloser, error)

ContainerExport retrieves the raw contents of a container and returns them as an io.ReadCloser. It's up to the caller to close the stream.

func (*Client) ContainerGetStatsChan added in v1.0.2

func (c *Client) ContainerGetStatsChan(ctx context.Context, containerConfig *container.ContainerConfig) (<-chan ContainerStats, <-chan error)

ContainerGetStatsChan returns near realtime stats for a given container. It is a blocking call that will not return until either: - The context is cancelled - The container is stopped - An error occurs Use context with timeout or cancellation to control the maximum wait time.

func (*Client) ContainerGetStatsOneShot added in v1.0.2

func (c *Client) ContainerGetStatsOneShot(ctx context.Context, containerConfig *container.ContainerConfig) (ContainerStats, error)

ContainerStatsOneShot gets a single stat entry from a container. It differs from `ContainerStats` in that the API should not wait to prime the stats

func (*Client) ContainerInspect added in v1.0.2

func (c *Client) ContainerInspect(ctx context.Context, containerConfig *container.ContainerConfig) (types.ContainerJSON, error)

ContainerInspect returns the JSON representation of a container. It returns docker's ContainerJSON type.

func (*Client) ContainerKill added in v1.0.2

func (c *Client) ContainerKill(ctx context.Context, containerConfig *container.ContainerConfig, signal string) error

ContainerKill kills a container.

func (*Client) ContainerList added in v1.0.2

func (c *Client) ContainerList(ctx context.Context, listOptionFns ...ListOptionFn) ([]ListedContainer, error)

func (*Client) ContainerPause added in v1.0.2

func (c *Client) ContainerPause(ctx context.Context, containerConfig *container.ContainerConfig) error

ContainerPause pauses a container.

func (*Client) ContainerPrune added in v1.0.2

func (c *Client) ContainerPrune(ctx context.Context, pruneOptions ...PruneOptionFn) (PruneResponse, error)

ContainerPrune prunes containers based on the provided options. It returns a PruneResponse containing the space reclaimed and the containers deleted. It uses the filters.Args type to build the filter for the prune operation.

func (*Client) ContainerRename added in v1.0.2

func (c *Client) ContainerRename(ctx context.Context, containerConfig *container.ContainerConfig, newName string) error

ContainerRename renames a container.

func (*Client) ContainerTop added in v1.0.2

func (c *Client) ContainerTop(ctx context.Context, containerConfig *container.ContainerConfig, psArgs []string) (ContainerTop, error)

ContainerTop returns the top process information for a container.

func (*Client) ContainerUnpause added in v1.0.2

func (c *Client) ContainerUnpause(ctx context.Context, containerConfig *container.ContainerConfig) error

ContainerUnpause unpauses a container.

func (*Client) ContainerUpdate added in v1.0.2

func (c *Client) ContainerUpdate(ctx context.Context, containerConfig *container.ContainerConfig, updateOptions ...UpdateOptionFn) (warnings []string, err error)

ContainerUpdate updates a container with new configuration.

func (*Client) ContainerWait

func (c *Client) ContainerWait(ctx context.Context, containerConfig *container.ContainerConfig) (<-chan containerType.WaitResponse, <-chan error)

ContainerWait waits for a container to finish and returns a channel for status and errors

func (*Client) CreateContainer

func (c *Client) CreateContainer(ctx context.Context, containerConfig *container.ContainerConfig) error

func (*Client) CreateNetwork

func (c *Client) CreateNetwork(ctx context.Context, networkConfig *network.NetworkConfig) error

func (*Client) CreateVolume

func (c *Client) CreateVolume(ctx context.Context, volumeConfig *volume.VolumeConfig) error

func (*Client) DisconnectContainerFromNetwork

func (c *Client) DisconnectContainerFromNetwork(ctx context.Context, networkConfig *network.NetworkConfig, containerConfig *container.ContainerConfig, force bool) error

func (*Client) GetContainerExitCode added in v1.0.2

func (c *Client) GetContainerExitCode(ctx context.Context, containerConfig *container.ContainerConfig) (int, error)

GetContainerExitCode returns the exit code of a container

func (*Client) GetContainerLogs

func (c *Client) GetContainerLogs(ctx context.Context, containerConfig *container.ContainerConfig) (io.ReadCloser, error)

GetContainerLogs returns a ReadCloser for container logs. If a custom log writer is configured, logs will also be written to it asynchronously. Caller is responsible for closing the returned reader.

func (*Client) GetContainerStats

func (c *Client) GetContainerStats(ctx context.Context, containerConfig *container.ContainerConfig) error

GetContainerStats gets stats and is synchronus This is a blocking call and will return when the container is stopped or the context is cancelled

func (*Client) GetImageCreatedTime added in v1.0.2

func (c *Client) GetImageCreatedTime(ctx context.Context, imageConfig *image.ImageConfig) (string, error)

GetImageCreatedTime returns when the image was created

func (*Client) GetImageSize added in v1.0.2

func (c *Client) GetImageSize(ctx context.Context, imageConfig *image.ImageConfig) (int64, error)

GetImageSize returns the size of an image in bytes

func (*Client) GetNetworkContainers added in v1.0.2

func (c *Client) GetNetworkContainers(ctx context.Context, networkConfig *network.NetworkConfig) ([]string, error)

GetNetworkContainers returns a list of container IDs connected to a network

func (*Client) GetVolumeUsage added in v1.0.2

func (c *Client) GetVolumeUsage(ctx context.Context, volumeConfig *volume.VolumeConfig) (int64, error)

GetVolumeUsage returns the size of a volume in bytes if available

func (*Client) IsContainerRunning added in v1.0.2

func (c *Client) IsContainerRunning(ctx context.Context, containerConfig *container.ContainerConfig) (bool, error)

IsContainerRunning checks if a container is currently running

func (*Client) IsNetworkExists added in v1.0.2

func (c *Client) IsNetworkExists(ctx context.Context, networkConfig *network.NetworkConfig) (bool, error)

IsNetworkExists checks if a network exists

func (*Client) IsVolumeExists added in v1.0.2

func (c *Client) IsVolumeExists(ctx context.Context, volumeConfig *volume.VolumeConfig) (bool, error)

IsVolumeExists checks if a volume exists

func (*Client) LoadImage

func (c *Client) LoadImage(ctx context.Context, inputFile string) error

func (*Client) PauseContainer

func (c *Client) PauseContainer(ctx context.Context, containerConfig *container.ContainerConfig) error

func (*Client) PruneImages added in v1.0.2

func (c *Client) PruneImages(ctx context.Context, pruneOptions ...PruneOptionFn) (ImagePruneResponse, error)

func (*Client) PruneVolumes

func (c *Client) PruneVolumes(ctx context.Context, filterMap map[string][]string) (uint64, error)

func (*Client) PullImage

func (c *Client) PullImage(ctx context.Context, imageConfig *image.ImageConfig) error

func (*Client) PullImageIfNotPresent added in v1.0.2

func (c *Client) PullImageIfNotPresent(ctx context.Context, imageConfig *image.ImageConfig) error

PullImageIfNotPresent pulls an image only if it doesn't exist locally

func (*Client) PushImage

func (c *Client) PushImage(ctx context.Context, imageConfig *image.ImageConfig) error

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(ctx context.Context, containerConfig *container.ContainerConfig, force bool) error

func (*Client) RemoveImage

func (c *Client) RemoveImage(ctx context.Context, imageConfig *image.ImageConfig, force bool) error

func (*Client) RemoveNetwork

func (c *Client) RemoveNetwork(ctx context.Context, networkConfig *network.NetworkConfig) error

func (*Client) RemoveVolume

func (c *Client) RemoveVolume(ctx context.Context, volumeConfig *volume.VolumeConfig) error

func (*Client) RestartContainer

func (c *Client) RestartContainer(ctx context.Context, containerConfig *container.ContainerConfig) error

func (*Client) RunAndWait added in v1.0.2

func (c *Client) RunAndWait(ctx context.Context, containerConfig *container.ContainerConfig) error

RunAndWait creates, starts a container and waits for it to finish. This is a blocking call that will not return until either: - The container finishes executing - An error occurs - The context is cancelled Use context with timeout or cancellation to control the maximum wait time.

func (*Client) RunAsync added in v1.0.2

func (c *Client) RunAsync(ctx context.Context, containerConfig *container.ContainerConfig) (<-chan error, error)

RunAsync creates and starts a container without waiting for it to finish. Returns a channel that will receive the container's exit error (if any). The channel will be closed when the container finishes.

func (*Client) SaveImage

func (c *Client) SaveImage(ctx context.Context, imageConfig *image.ImageConfig, outputFile string) error

func (*Client) SetImageResponeWriter

func (c *Client) SetImageResponeWriter(dst io.Writer)

SetImageResponeWriter sets the image response writer for Docker's API. If this is not set, the client wrapper will default to stdout.

func (*Client) SetLogResponseWriter

func (c *Client) SetLogResponseWriter(dst io.Writer)

This sets the log output response writer for Docker's API. If this is not set, the client wrapper will default to stdout.

func (*Client) SetStatsResponeWriter

func (c *Client) SetStatsResponeWriter(dst io.Writer)

This sets the stats response writer for Docker's API. If this is not set, the client wrapper will default to StatsFormatter.

func (*Client) StartContainer

func (c *Client) StartContainer(ctx context.Context, containerConfig *container.ContainerConfig) error

func (*Client) StopContainer

func (c *Client) StopContainer(ctx context.Context, containerConfig *container.ContainerConfig) error

func (*Client) String

func (c *Client) String() string

func (*Client) TagImage

func (c *Client) TagImage(ctx context.Context, imageConfig *image.ImageConfig, newTag string) error

func (*Client) UnpauseContainer

func (c *Client) UnpauseContainer(ctx context.Context, containerConfig *container.ContainerConfig) error

func (*Client) Unwrap

func (c *Client) Unwrap() client.APIClient

Unwraps the abstracted client for use with other docker packages

type ContainerStats

type ContainerStats struct {
	Read         time.Time               `json:"read"`
	Preread      time.Time               `json:"preread"`
	PidsStats    container.PidsStats     `json:"pids_stats"`
	BlkioStats   container.BlkioStats    `json:"blkio_stats"`
	NumProcs     int64                   `json:"num_procs"`
	StorageStats container.StorageStats  `json:"storage_stats"`
	CpuStats     container.CPUStats      `json:"cpu_stats"`
	PreCPUStats  container.CPUStats      `json:"precpu_stats"`
	MemoryStats  container.MemoryStats   `json:"memory_stats"`
	Networks     map[string]NetworkStats `json:"networks"`
}

func (*ContainerStats) FormatCpuUsagePercentage

func (stats *ContainerStats) FormatCpuUsagePercentage() string

func (*ContainerStats) FormatDiskIO

func (stats *ContainerStats) FormatDiskIO() string

func (*ContainerStats) FormatMemoryUsage

func (stats *ContainerStats) FormatMemoryUsage() string

func (*ContainerStats) FormatNetworkIO

func (stats *ContainerStats) FormatNetworkIO() string

type ContainerTop added in v1.0.2

type ContainerTop struct {

	// Each process running in the container, where each is process
	// is an array of values corresponding to the titles.
	//
	// Required: true
	Processes [][]string `json:"Processes"`

	// The ps column titles
	// Required: true
	Titles []string `json:"Titles"`
}

ContainerTop is the response from the ContainerTop API.

type Diff added in v1.0.2

type Diff struct {
	Path string `json:"Path"`
	Kind uint8  `json:"Kind"`
}

Diff is the response from the ContainerDiff API.

type ExecInspect added in v1.0.2

type ExecInspect struct {
	ExecID      string `json:"ID,omitempty"`
	ContainerID string `json:"ContainerID,omitempty"`
	Running     bool   `json:"Running,omitempty"`
	ExitCode    int    `json:"ExitCode,omitempty"`
	Pid         int    `json:"Pid,omitempty"`
}

type FormatedContainerStats

type FormatedContainerStats struct {
	CpuUsage    string `json:"cpuUsage"`
	MemoryUsage string `json:"memoryUsage"`
	NetworkIO   string `json:"networkIO"`
	DiskIO      string `json:"diskIO"`
}

type ImageProgress

type ImageProgress struct {
	Stream   string `json:"stream,omitempty"`
	Status   string `json:"status,omitempty"`
	Progress string `json:"progress,omitempty"`
	Aux      struct {
		ID string `json:"id,omitempty"`
	} `json:"aux,omitempty"`
	ErrorDetail struct {
		Message string `json:"message,omitempty"`
	} `json:"errorDetail,omitempty"`
	Error string `json:"error,omitempty"`
}

ImageProgress represents the JSON output from Docker image operations

type ImagePruneResponse added in v1.0.2

type ImagePruneResponse struct {
	SpaceReclaimed uint64   `json:"SpaceReclaimed,omitempty"`
	ImagesDeleted  []string `json:"ImagesDeleted,omitempty"`
}

type ListOptionFn added in v1.0.2

type ListOptionFn func(*containerType.ListOptions)

type ListedContainer added in v1.0.2

type ListedContainer struct {
	ID         string       `json:"Id,omitempty"`
	Names      []string     `json:"Names,omitempty"`
	Image      string       `json:"Image,omitempty"`
	ImageID    string       `json:"ImageID,omitempty"`
	Command    string       `json:"Command,omitempty"`
	Created    int64        `json:"Created,omitempty"`
	Ports      []types.Port `json:"Ports,omitempty"`
	SizeRw     int64        `json:"SizeRw,omitempty"`
	SizeRootFs int64        `json:"SizeRootFs,omitempty"`
	Labels     map[string]string
	State      string `json:"State,omitempty"`
	Status     string `json:"Status,omitempty"`
	HostConfig struct {
		NetworkMode string            `json:"NetworkMode,omitempty"`
		Annotations map[string]string `json:"Annotations,omitempty"`
	}
	NetworkSettings *types.SummaryNetworkSettings `json:"NetworkSettings,omitempty"`
	Mounts          []types.MountPoint            `json:"Mounts,omitempty"`
}

ListedContainer is the response from the ContainerList API.

type LogCopier added in v1.0.1

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

LogCopier provides methods to copy Docker container logs

func NewLogCopier added in v1.0.1

func NewLogCopier(stdout io.Writer, stderr io.Writer) *LogCopier

NewLogCopier creates a new LogCopier instance If stderr is nil, it will use stdout for both streams

func (*LogCopier) Copy added in v1.0.1

func (lc *LogCopier) Copy(src io.Reader) (written int64, err error)

Copy copies the container log stream to the configured writers It handles Docker's multiplexed output format where stdout and stderr are combined with headers

func (*LogCopier) CopyWithPrefix added in v1.0.1

func (lc *LogCopier) CopyWithPrefix(src io.Reader, stdoutPrefix, stderrPrefix string) (written int64, err error)

CopyWithPrefix copies the container log stream and adds prefixes to stdout and stderr This is useful when you want to distinguish between the two streams in the output

type NetworkStats added in v1.0.2

type NetworkStats struct {
	RxBytes   uint64 `json:"rx_bytes"`
	RxDropped uint64 `json:"rx_dropped"`
	RxErrors  uint64 `json:"rx_errors"`
	RxPackets uint64 `json:"rx_packets"`
	TxBytes   uint64 `json:"tx_bytes"`
	TxDropped uint64 `json:"tx_dropped"`
	TxErrors  uint64 `json:"tx_errors"`
	TxPackets uint64 `json:"tx_packets"`
}

type PruneOptionFn added in v1.0.2

type PruneOptionFn func(*filters.Args)

func WithPruneFilter added in v1.0.2

func WithPruneFilter(key, value string) PruneOptionFn

WithPruneFilter adds a filter to the prune operation.

type PruneResponse added in v1.0.2

type PruneResponse struct {
	SpaceReclaimed    uint64   `json:"SpaceReclaimed,omitempty"`
	ContainersDeleted []string `json:"ContainersDeleted,omitempty"`
}

type UpdateOptionFn added in v1.0.2

type UpdateOptionFn func(*containerType.UpdateConfig)

UpdateOptionFn is a function that can be used to update a container.

Jump to

Keyboard shortcuts

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