docker

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateCreated    = container.StateCreated
	StateRunning    = container.StateRunning
	StatePaused     = container.StatePaused
	StateRestarting = container.StateRestarting
	StateRemoving   = container.StateRemoving
	StateExited     = container.StateExited
	StateDead       = container.StateDead
)

Variables

View Source
var (
	ErrComposeNotAvailable = errors.New("Docker Compose is not available on this system")

	// DefaultComposeFileNames contains standard filenames for Docker Compose definitions in order of precedence.
	DefaultComposeFileNames = []string{
		"compose.yaml",
		"compose.yml",
		"docker-compose.yaml",
		"docker-compose.yml",
	}
)
View Source
var ErrMustStopContainer = errors.New("container must be stopped before removal")

Functions

func CleanImageID

func CleanImageID(id string) string

func CleanLayerCommand

func CleanLayerCommand(cmd string) string

CleanLayerCommand returns a single-line, Dockerfile-like instruction from a history CreatedBy string.

func FindComposeFile added in v0.4.0

func FindComposeFile(configFiles, workingDir string) string

FindComposeFile attempts to locate an existing compose file from comma-separated configFiles or workingDir.

func FindComposeFileInAncestors added in v0.4.0

func FindComposeFileInAncestors(dir string) (filePath string, foundDir string)

FindComposeFileInAncestors starts at dir and walks up parent directories until a compose file is found. It returns the path to the compose file and the directory containing it. If dir is empty, it uses the current working directory.

func FormatImageSize

func FormatImageSize(size int64) string

func FormatTimeAgo

func FormatTimeAgo(t time.Time) string

FormatTimeAgo formats a time into a relative "X ago" string.

func IsContainerLifecycleEvent

func IsContainerLifecycleEvent(action events.Action) bool

IsContainerLifecycleEvent returns true if the event represents an actual state/lifecycle change of a container.

func IsImageLifecycleEvent

func IsImageLifecycleEvent(action events.Action) bool

IsImageLifecycleEvent returns true if the event represents an addition, removal, or tag change of an image.

func IsNetworkLifecycleEvent

func IsNetworkLifecycleEvent(action events.Action) bool

IsNetworkLifecycleEvent returns true if the event represents a network lifecycle modification.

func IsVolumeLifecycleEvent

func IsVolumeLifecycleEvent(action events.Action) bool

IsVolumeLifecycleEvent returns true if the event represents a volume lifecycle modification.

func NormalizeProjectName added in v0.4.0

func NormalizeProjectName(s string) string

NormalizeProjectName converts a directory or project name to a valid compose project name by lowercasing and stripping characters that are not [a-z0-9_-].

func OpenBrowser added in v0.3.1

func OpenBrowser(url string) error

OpenBrowser opens the given URL in the user's default web browser.

func ResolveExistingFile added in v0.4.0

func ResolveExistingFile(path string) string

ResolveExistingFile checks if a path exists, handling Windows/WSL2 path conversions if applicable.

func ShortID

func ShortID(id string) string

Types

type Client

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

func NewClient

func NewClient(hosts ...string) (*Client, error)

NewClient initializes a Docker API client using intelligent multi-tier host resolution.

The optional hosts parameter allows callers to pass an explicit endpoint (e.g. from CLI flag -H/--host or config file). If multiple hosts are provided, only the first non-empty one is used.

Host resolution precedence:

  1. Explicit host argument passed to NewClient (if non-empty)
  2. DOCKER_HOST environment variable (if set and non-empty)
  3. Active Docker context from ~/.docker/config.json or $DOCKER_CONTEXT
  4. Probed local daemon sockets (macOS user sockets, Windows WSL2 named pipe, Linux rootless)
  5. Standard Moby default socket (/var/run/docker.sock)

Upon successful client initialization, NewClient immediately executes a Ping with a 5-second timeout to negotiate the API version and ensure daemon reachability before returning.

func (*Client) AttachShellCmd added in v0.3.1

func (c *Client) AttachShellCmd(containerID string) *exec.Cmd

func (*Client) Close

func (c *Client) Close() error

func (*Client) ComposeBuildCmd added in v0.4.0

func (c *Client) ComposeBuildCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)

ComposeBuildCmd returns a command to build images and start services in detached mode.

func (*Client) ComposeDownCmd added in v0.4.0

func (c *Client) ComposeDownCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)

ComposeDownCmd returns a command to stop and remove containers, networks created by compose.

func (*Client) ComposeLogsCmd added in v0.4.0

func (c *Client) ComposeLogsCmd(ctx context.Context, opts ComposeOpts, tail string) (*exec.Cmd, error)

ComposeLogsCmd returns a command to stream compose logs.

func (*Client) ComposeRestartCmd added in v0.4.0

func (c *Client) ComposeRestartCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)

ComposeRestartCmd returns a command to restart compose services.

func (*Client) ComposeRmCmd added in v0.4.0

func (c *Client) ComposeRmCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)

ComposeRmCmd returns a command to remove stopped service containers.

func (*Client) ComposeStartCmd added in v0.4.0

func (c *Client) ComposeStartCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)

ComposeStartCmd returns a command to start stopped compose services.

func (*Client) ComposeStopCmd added in v0.4.0

func (c *Client) ComposeStopCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)

ComposeStopCmd returns a command to stop compose services.

func (*Client) ComposeUpCmd added in v0.4.0

func (c *Client) ComposeUpCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)

ComposeUpCmd returns a command to start services in detached mode.

func (*Client) ContainerTop

func (c *Client) ContainerTop(ctx context.Context, containerID string) (*container.TopResponse, error)

func (*Client) ExecShellCmd

func (c *Client) ExecShellCmd(containerID string) *exec.Cmd

func (*Client) GetImageHistory

func (c *Client) GetImageHistory(ctx context.Context, imageID string) ([]ImageLayer, error)

GetImageHistory fetches layers history for an image.

func (*Client) Host added in v0.2.0

func (c *Client) Host() string

Host returns the configured Docker host endpoint, if any.

func (*Client) InspectContainer

func (c *Client) InspectContainer(ctx context.Context, containerID string) (*container.InspectResponse, error)

func (*Client) InspectImage

func (c *Client) InspectImage(ctx context.Context, imageID string) (*image.InspectResponse, error)

InspectImage fetches full inspection metadata for an image.

func (*Client) InspectNetwork

func (c *Client) InspectNetwork(ctx context.Context, networkID string) (*network.Inspect, error)

InspectNetwork fetches full inspection metadata for a network

func (*Client) InspectVolume

func (c *Client) InspectVolume(ctx context.Context, name string) (*volume.Volume, error)

InspectVolume retrieves deep inspect data for a volume

func (*Client) ListContainers

func (c *Client) ListContainers(ctx context.Context) ([]ContainerInfo, error)

Docker container cmd

func (*Client) ListImages

func (c *Client) ListImages(ctx context.Context) ([]ImageInfo, error)

ListImages retrieves images and annotates them with container usage and status.

func (*Client) ListNetworks

func (c *Client) ListNetworks(ctx context.Context) ([]NetworkInfo, error)

ListNetworks retrieves all Docker networks with detailed endpoint metadata

func (*Client) ListVolumes

func (c *Client) ListVolumes(ctx context.Context) ([]VolumeInfo, error)

ListVolumes retrieves all docker volumes and cross-references them with active/stopped containers

func (*Client) PauseContainer

func (c *Client) PauseContainer(ctx context.Context, containerID string) error

func (*Client) Ping

func (c *Client) Ping() error

func (*Client) PruneContainers

func (c *Client) PruneContainers(ctx context.Context) (container.PruneReport, error)

func (*Client) PruneImages

func (c *Client) PruneImages(ctx context.Context) (image.PruneReport, error)

PruneImages removes dangling images.

func (*Client) PruneNetworks

func (c *Client) PruneNetworks(ctx context.Context) (network.PruneReport, error)

PruneNetworks removes unused networks

func (*Client) PruneVolumes

func (c *Client) PruneVolumes(ctx context.Context) (volume.PruneReport, error)

PruneVolumes removes all unused local volumes

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(ctx context.Context, id string, opts RemoveContainerOpts) error

func (*Client) RemoveImage

func (c *Client) RemoveImage(ctx context.Context, imageID string, force bool) error

RemoveImage deletes an image by ID or tag.

func (*Client) RemoveNetwork

func (c *Client) RemoveNetwork(ctx context.Context, networkID string) error

RemoveNetwork deletes a network by ID or name

func (*Client) RemoveVolume

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

RemoveVolume deletes a volume by name

func (*Client) RestartContainer

func (c *Client) RestartContainer(ctx context.Context, containerID string) error

func (*Client) StartContainer

func (c *Client) StartContainer(ctx context.Context, containerID string) error

func (*Client) StopContainer

func (c *Client) StopContainer(ctx context.Context, containerID string) error

func (*Client) StreamComposeLogs

func (c *Client) StreamComposeLogs(ctx context.Context, opts ComposeLogOpts) <-chan string

func (*Client) StreamContainerLogs

func (c *Client) StreamContainerLogs(ctx context.Context, id string, tail string) <-chan string

func (*Client) StreamContainerStats

func (c *Client) StreamContainerStats(ctx context.Context, containerID string) <-chan ContainerMetrics

func (*Client) StreamEvents

func (c *Client) StreamEvents(ctx context.Context) (<-chan events.Message, <-chan error)

func (*Client) UnpauseContainer

func (c *Client) UnpauseContainer(ctx context.Context, containerID string) error

type ComposeCommandType added in v0.4.0

type ComposeCommandType string

ComposeCommandType represents the variant of Docker Compose available on the host.

const (
	ComposeV2   ComposeCommandType = "docker compose"
	ComposeV1   ComposeCommandType = "docker-compose"
	ComposeNone ComposeCommandType = "none"
)

type ComposeLogOpts

type ComposeLogOpts struct {
	WorkingDir  string
	ConfigFile  string
	ProjectName string
	Service     string
	Tail        string
}

type ComposeOpts added in v0.4.0

type ComposeOpts struct {
	ProjectName string
	Service     string
	WorkingDir  string
	ConfigFile  string
}

ComposeOpts specifies parameters to target a Docker Compose project or service.

type ComposeService added in v0.4.0

type ComposeService interface {
	ComposeUpCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)
	ComposeBuildCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)
	ComposeDownCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)
	ComposeRestartCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)
	ComposeStopCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)
	ComposeStartCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)
	ComposeRmCmd(ctx context.Context, opts ComposeOpts) (*exec.Cmd, error)
	StreamComposeLogs(ctx context.Context, opts ComposeLogOpts) <-chan string
}

ComposeService defines lifecycle commands for Docker Compose projects and services.

type ContainerInfo

type ContainerInfo struct {
	ID     string
	Name   string
	Image  string
	Status string
	State  container.ContainerState
	Ports  string

	// Doker Compose labels
	IsCompose       bool
	ProjectName     string
	Service         string
	ContainerNumber int
	OneOff          bool
	ConfigFiles     string
	WorkingDir      string

	Details *container.InspectResponse
}

func (*ContainerInfo) HasDetailsLoaded

func (c *ContainerInfo) HasDetailsLoaded() bool

func (*ContainerInfo) ShortID

func (c *ContainerInfo) ShortID() string

func (ContainerInfo) WebURL added in v0.3.1

func (c ContainerInfo) WebURL() (string, bool)

type ContainerMetrics

type ContainerMetrics struct {
	CPUPercent  float64
	MemUsage    float64
	MemLimit    float64
	HasMemLimit bool
	NetworkRx   float64
	NetworkTx   float64
	BlockRead   uint64
	BlockWrite  uint64
}

type ContainerService

type ContainerService interface {
	ListContainers(ctx context.Context) ([]ContainerInfo, error)
	InspectContainer(ctx context.Context, containerID string) (*container.InspectResponse, error)
	ContainerTop(ctx context.Context, containerID string) (*container.TopResponse, error)
	StartContainer(ctx context.Context, containerID string) error
	StopContainer(ctx context.Context, containerID string) error
	RestartContainer(ctx context.Context, containerID string) error
	PauseContainer(ctx context.Context, containerID string) error
	UnpauseContainer(ctx context.Context, containerID string) error
	RemoveContainer(ctx context.Context, id string, opts RemoveContainerOpts) error
	PruneContainers(ctx context.Context) (container.PruneReport, error)
	ExecShellCmd(containerID string) *exec.Cmd
	AttachShellCmd(containerID string) *exec.Cmd
	StreamContainerLogs(ctx context.Context, containerID string, tail string) <-chan string
	StreamContainerStats(ctx context.Context, id string) <-chan ContainerMetrics
	ComposeService
}

ContainerService defines the narrow interface required by Container components.

type ContainerState added in v0.2.0

type ContainerState = container.ContainerState

type EventService

type EventService interface {
	StreamEvents(ctx context.Context) (<-chan events.Message, <-chan error)
}

EventService defines daemon lifecycle streaming.

type ImageInfo

type ImageInfo struct {
	ID               string
	RepoTags         []string
	Tag              string
	Size             int64
	Created          time.Time
	InUse            bool
	Dangling         bool
	UsedByContainers []string
	Details          *image.InspectResponse
	Layers           []ImageLayer
}

type ImageLayer

type ImageLayer struct {
	Index   int
	ID      string
	Size    int64
	Command string
	Created time.Time
	Comment string
}

type ImageService

type ImageService interface {
	ListImages(ctx context.Context) ([]ImageInfo, error)
	InspectImage(ctx context.Context, id string) (*image.InspectResponse, error)
	GetImageHistory(ctx context.Context, id string) ([]ImageLayer, error)
	RemoveImage(ctx context.Context, id string, force bool) error
	PruneImages(ctx context.Context) (image.PruneReport, error)
}

ImageService defines the narrow interface required by Image components.

type LocalComposeProject added in v0.4.0

type LocalComposeProject struct {
	ProjectName string
	WorkingDir  string
	ConfigFile  string
	Services    []string
}

LocalComposeProject holds metadata discovered from a local compose file.

func DetectLocalCompose added in v0.4.0

func DetectLocalCompose(dir string) (*LocalComposeProject, error)

DetectLocalCompose scans the given directory and its parent directories for compose files and parses service names. If dir is empty, it uses the current working directory.

type NetworkEndpointInfo

type NetworkEndpointInfo struct {
	ContainerID string
	Name        string
	IP          string
	MacAddress  string
	Ports       string
}

NetworkEndpointInfo represents a container connected to a network

type NetworkInfo

type NetworkInfo struct {
	network.Summary
	Subnet         string
	Gateway        string
	IsSystem       bool
	ConnectedCount int
	Containers     []NetworkEndpointInfo
}

type NetworkService

type NetworkService interface {
	ListNetworks(ctx context.Context) ([]NetworkInfo, error)
	InspectNetwork(ctx context.Context, id string) (*network.Inspect, error)
	RemoveNetwork(ctx context.Context, id string) error
	PruneNetworks(ctx context.Context) (network.PruneReport, error)
}

NetworkService defines the narrow interface required by Network components.

type RemoveContainerOpts

type RemoveContainerOpts struct {
	RemoveVolumes bool
	Force         bool
}

type Service

type Service interface {
	ContainerService
	ImageService
	VolumeService
	NetworkService
	EventService
	Host() string
	Close() error
	Ping() error
}

Service is an idiomatic composite interface combining all domain sub-services. Used by the root AppModel to orchestrate all tabs and engine events.

type VolumeContainerMount

type VolumeContainerMount struct {
	ContainerID   string
	ContainerName string
	State         container.ContainerState
	Destination   string
	Mode          string
	RW            bool
}

VolumeContainerMount describes a container currently mounting a volume

type VolumeInfo

type VolumeInfo struct {
	volume.Volume
	InUse      bool
	RefCnt     int
	Containers []VolumeContainerMount
}

VolumeInfo encapsulates metadata and live container usage for a Docker volume

type VolumeService

type VolumeService interface {
	ListVolumes(ctx context.Context) ([]VolumeInfo, error)
	InspectVolume(ctx context.Context, name string) (*volume.Volume, error)
	RemoveVolume(ctx context.Context, name string, force bool) error
	PruneVolumes(ctx context.Context) (volume.PruneReport, error)
}

VolumeService defines the narrow interface required by Volume components.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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