godock

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 28 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) ContainerCreate added in v1.1.2

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

func (*Client) ContainerDiff added in v1.0.2

func (c *Client) ContainerDiff(ctx context.Context, containerConfig *container.ContainerConfig) ([]containerType.FilesystemChange, 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, execID string, 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) ContainerExecCreate added in v1.1.2

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

func (*Client) ContainerExecInspect added in v1.0.2

func (c *Client) ContainerExecInspect(ctx context.Context, execConfig *exec.ExecConfig) (*containerType.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) 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 ...ListContainerOptionFn) ([]types.Container, error)

ContainerList lists all containers. provide option functions to filter the list.

func (*Client) ContainerLogs added in v1.1.2

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

ContainerLogs returns a ReadCloser for container logs. Caller is responsible for closing the returned reader.

func (*Client) ContainerPause added in v1.0.2

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

func (*Client) ContainerPrune added in v1.0.2

func (c *Client) ContainerPrune(ctx context.Context, pruneOptions ...PruneOptionFn) (*containerType.PruneReport, 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) ContainerRemove added in v1.1.2

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

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) ContainerRestart added in v1.1.2

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

func (*Client) ContainerStart added in v1.1.2

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

func (*Client) ContainerStats added in v1.1.2

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

ContainerStats 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) ContainerStatsChan added in v1.1.2

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

ContainerStatsChan 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) ContainerStatsOneShot added in v1.1.2

func (c *Client) ContainerStatsOneShot(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) ContainerStop added in v1.1.2

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

func (*Client) ContainerTop added in v1.0.2

func (c *Client) ContainerTop(ctx context.Context, containerConfig *container.ContainerConfig, psArgs []string) (*containerType.ContainerTopOKBody, 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

func (*Client) ContainerUpdate added in v1.0.2

func (c *Client) ContainerUpdate(ctx context.Context, containerConfig *container.ContainerConfig, updateOptions ...UpdateOptionFn) (*containerType.ContainerUpdateOKBody, 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) 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) 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) ImageBuild added in v1.1.2

func (c *Client) ImageBuild(ctx context.Context, imageConfig *image.ImageConfig) (io.ReadCloser, error)

BuildImage builds an image from a directory or a context If the context is not included in the image config, it will return an error Caller is responsible for closing the response body

func (*Client) ImageCommit added in v1.1.2

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

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

func (*Client) ImageHistory added in v1.1.2

func (c *Client) ImageHistory(ctx context.Context, imageID string) ([]imageType.HistoryResponseItem, error)

func (*Client) ImageInspect added in v1.1.2

func (c *Client) ImageInspect(ctx context.Context, imageID string) (*types.ImageInspect, error)

func (*Client) ImageList added in v1.1.2

func (c *Client) ImageList(ctx context.Context, imageListOptionFns ...ImageListOptionFn) ([]imageType.Summary, error)

func (*Client) ImageLoad added in v1.1.2

func (c *Client) ImageLoad(ctx context.Context, inputFile string) (io.ReadCloser, error)

func (*Client) ImageLoadFromReader added in v1.1.2

func (c *Client) ImageLoadFromReader(ctx context.Context, input io.Reader, quiet bool) (*imageType.LoadResponse, error)

ImageLoad loads an image in the docker host from the client host. It's up to the caller to close the io.ReadCloser in the ImageLoadResponse returned by this function

func (*Client) ImagePull added in v1.1.2

func (c *Client) ImagePull(ctx context.Context, imageConfig *image.ImageConfig) (io.ReadCloser, error)

PullImage requests the docker host to pull an image from a remote registry. It executes the privileged function if the operation is unauthorized and it tries one more time. It's up to the caller to handle the io.ReadCloser and close it properly.

func (*Client) ImagePush added in v1.1.2

func (c *Client) ImagePush(ctx context.Context, imageConfig *image.ImageConfig) (io.ReadCloser, error)

func (*Client) ImageRemove added in v1.1.2

func (c *Client) ImageRemove(ctx context.Context, imageID string, force bool, pruneChildren bool) ([]imageType.DeleteResponse, error)

func (*Client) ImageSave added in v1.1.2

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

func (*Client) ImageSaveToReader added in v1.1.2

func (c *Client) ImageSaveToReader(ctx context.Context, imageIDs []string) (io.ReadCloser, error)

ImageSave retrieves one or more images from the docker host as an io.ReadCloser. It's up to the caller to store the images and close the stream.

func (*Client) ImageSearch added in v1.1.2

func (c *Client) ImageSearch(ctx context.Context, query string, opts ...ImageSearchOptionFn) ([]registry.SearchResult, error)

ImageSearch searches for an image on Docker Hub. The query parameter specifies the term to search for. Returns a slice of SearchResult containing the search results.

func (*Client) ImageTag added in v1.1.2

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

func (*Client) ImagesPrune added in v1.1.2

func (c *Client) ImagesPrune(ctx context.Context, pruneOptions ...PruneOptionFn) (*imageType.PruneReport, error)

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) NetworkConnect added in v1.1.2

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

func (*Client) NetworkConnectContainer added in v1.1.2

func (c *Client) NetworkConnectContainer(ctx context.Context, networkID string, containerID string, endpoint *endpointoptions.Endpoint) error

NetworkConnect connects a container to a network.

func (*Client) NetworkCreate added in v1.1.2

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

func (*Client) NetworkDisconnect added in v1.1.2

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

func (*Client) NetworkDisconnectContainer added in v1.1.2

func (c *Client) NetworkDisconnectContainer(ctx context.Context, networkID string, containerID string, force bool) error

NetworkDisconnect disconnects a container from a network.

func (*Client) NetworkInspect added in v1.1.2

func (c *Client) NetworkInspect(ctx context.Context, networkID string, networkInspectOptionFns ...NetworkInspectOptionFn) (dockerNetwork.Inspect, error)

func (*Client) NetworkList added in v1.1.2

func (c *Client) NetworkList(ctx context.Context, networkListOptionFns ...NetworkListOptionFn) ([]dockerNetwork.Summary, error)

func (*Client) NetworkRemove added in v1.1.2

func (c *Client) NetworkRemove(ctx context.Context, networkID string) 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) String

func (c *Client) String() string

func (*Client) Unwrap

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

Unwraps the abstracted client for use with other docker packages

func (*Client) VolumeCreate added in v1.1.2

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

func (*Client) VolumeList added in v1.1.2

func (c *Client) VolumeList(ctx context.Context, volumeListOptionFns ...VolumeListOptionFn) (volumeType.ListResponse, error)

func (*Client) VolumePrune added in v1.1.2

func (c *Client) VolumePrune(ctx context.Context, pruneVolumeOptionFns ...PruneVolumeOptionFn) (*volumeType.PruneReport, error)

func (*Client) VolumeRemove added in v1.1.2

func (c *Client) VolumeRemove(ctx context.Context, name string, force bool) error

func (*Client) VolumeUsage added in v1.1.2

func (c *Client) VolumeUsage(ctx context.Context, name string) (*volumeType.UsageData, error)

GetVolumeUsage returns the size of a volume in bytes if available

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 FormatedContainerStats

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

type ImageListOptionFn added in v1.1.2

type ImageListOptionFn func(*imageType.ListOptions)

func WithImageAll added in v1.1.2

func WithImageAll(all bool) ImageListOptionFn

WithImageAll sets the all flag to true in the image list operation.

func WithImageContainerCount added in v1.1.2

func WithImageContainerCount(containerCount bool) ImageListOptionFn

WithImageContainerCount sets the container count flag to true in the image list operation.

func WithImageFilter added in v1.1.2

func WithImageFilter(key, value string) ImageListOptionFn

WithImageFilter adds a filter to the image list operation.

func WithImageManifests added in v1.1.2

func WithImageManifests(manifests bool) ImageListOptionFn

WithImageManifests sets the manifests flag to true in the image list operation.

func WithImageSharedSize added in v1.1.2

func WithImageSharedSize(sharedSize bool) ImageListOptionFn

WithImageSharedSize sets the shared size flag to true in the image list operation.

type ImageSearchOptionFn added in v1.1.2

type ImageSearchOptionFn func(*registry.SearchOptions)

ImageSearchOptionFn is a function type that configures search options for Docker images.

func WithSearchFilters added in v1.1.2

func WithSearchFilters(filters filters.Args) ImageSearchOptionFn

WithSearchFilters adds filters to the search operation.

func WithSearchLimit added in v1.1.2

func WithSearchLimit(limit int) ImageSearchOptionFn

WithSearchLimit sets the maximum number of search results to return. The limit must be between 1 and 100.

type ListContainerOptionFn added in v1.1.2

type ListContainerOptionFn func(*containerType.ListOptions)

func WithContainerAll added in v1.1.2

func WithContainerAll(all bool) ListContainerOptionFn

WithContainerAll sets the all flag to true in the container list operation.

func WithContainerBefore added in v1.1.2

func WithContainerBefore(before string) ListContainerOptionFn

WithContainerBefore sets the before flag to true in the container list operation.

func WithContainerFilter added in v1.1.2

func WithContainerFilter(key, value string) ListContainerOptionFn

WithContainerFilter adds a filter to the container list operation.

func WithContainerLimit added in v1.1.2

func WithContainerLimit(limit int) ListContainerOptionFn

WithContainerLimit sets the limit of the container list operation.

func WithContainerSince added in v1.1.2

func WithContainerSince(since string) ListContainerOptionFn

WithContainerSince sets the since flag to true in the container list operation.

func WithContainerSize added in v1.1.2

func WithContainerSize(size bool) ListContainerOptionFn

WithContainerSize sets the size flag to true in the container list operation.

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 NetworkInspectOptionFn added in v1.1.2

type NetworkInspectOptionFn func(*dockerNetwork.InspectOptions)

func WithNetworkInspectScope added in v1.1.2

func WithNetworkInspectScope(scope string) NetworkInspectOptionFn

WithNetworkInspectScope sets the scope of the network inspect operation.

func WithNetworkInspectVerbose added in v1.1.2

func WithNetworkInspectVerbose() NetworkInspectOptionFn

WithNetworkInspectVerbose sets the verbose flag to true in the network inspect operation.

type NetworkListOptionFn added in v1.1.2

type NetworkListOptionFn func(*dockerNetwork.ListOptions)

func WithNetworkFilter added in v1.1.2

func WithNetworkFilter(key, value string) NetworkListOptionFn

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 PruneVolumeOptionFn added in v1.1.2

type PruneVolumeOptionFn func(*filters.Args)

func FilterExcludeLabel added in v1.1.2

func FilterExcludeLabel(key string) PruneVolumeOptionFn

FilterExcludeLabel adds a filter to keep volumes that don't have the specified label key. Example: FilterExcludeLabel("env") keeps volumes without label "env"

func FilterExcludeLabelValue added in v1.1.2

func FilterExcludeLabelValue(key, value string) PruneVolumeOptionFn

FilterExcludeLabelValue adds a filter to keep volumes without the specified label key=value. Example: FilterExcludeLabelValue("env", "prod") keeps volumes without label env=prod

func FilterIncludeLabel added in v1.1.2

func FilterIncludeLabel(key string) PruneVolumeOptionFn

FilterIncludeLabel adds a filter to keep volumes that have the specified label key (any value). Example: FilterIncludeLabel("env") keeps volumes with label "env"

func FilterIncludeLabelValue added in v1.1.2

func FilterIncludeLabelValue(key, value string) PruneVolumeOptionFn

FilterIncludeLabelValue adds a filter to keep volumes with the specified label key=value. Example: FilterIncludeLabelValue("env", "prod") keeps volumes with label env=prod

type UpdateOptionFn added in v1.0.2

type UpdateOptionFn func(*containerType.UpdateConfig)

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

type VolumeListOptionFn added in v1.1.2

type VolumeListOptionFn func(*volumeType.ListOptions)

func WithVolumeFilter added in v1.1.2

func WithVolumeFilter(key, value string) VolumeListOptionFn

Directories

Path Synopsis
Package errors provides custom error types for the godock client
Package errors provides custom error types for the godock client

Jump to

Keyboard shortcuts

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