docker

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// VolumeTypeVolume represents a named volume mount
	VolumeTypeVolume = "volume"
	// VolumeTypeBind represents a bind mount
	VolumeTypeBind = "bind"
	// VolumeTypeTmpfs represents a tmpfs mount
	VolumeTypeTmpfs = "tmpfs"
)

Variables

View Source
var (
	ErrContainerNotHealthy = errors.New("container did not become healthy within timeout")
	ErrContainerNotRunning = errors.New("container is not running")
	ErrImagePullFailed     = errors.New("image pull failed")
)
View Source
var (
	// ErrTmpfsNoHostPath indicates tmpfs volumes don't have host paths
	ErrTmpfsNoHostPath = errors.New("tmpfs volumes don't have host paths")
	// ErrUnknownVolumeType indicates an unknown volume type was encountered
	ErrUnknownVolumeType = errors.New("unknown volume type")
)

Functions

func NewClient

func NewClient() (client.APIClient, error)

NewClient creates a new Docker client with default settings

Types

type ContainerConfig

type ContainerConfig struct {
	Image         string
	Name          string
	Env           []string
	Binds         []string
	PortBindings  nat.PortMap
	ExposedPorts  nat.PortSet
	Cmd           []string
	WorkingDir    string
	Labels        map[string]string
	Networks      map[string]*network.EndpointSettings
	RestartPolicy container.RestartPolicy
}

ContainerConfig defines the configuration for starting a container

type ContainerHealth

type ContainerHealth struct {
	Status string
}

ContainerHealth represents container health information

type ContainerInfo

type ContainerInfo struct {
	ID       string
	Name     string
	Status   string
	Image    string
	Ports    []Port
	Labels   map[string]string
	Networks map[string]*network.EndpointSettings
}

ContainerInfo contains information about a running container

type ContainerJSON

type ContainerJSON struct {
	Name            string
	State           ContainerState
	Config          DockerContainerConfig
	NetworkSettings *ContainerNetworkSettings
}

ContainerJSON represents a Docker container's detailed information

type ContainerManager

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

ContainerManager handles Docker container operations

func NewContainerManager

func NewContainerManager(dockerClient client.APIClient, logger logrus.FieldLogger) *ContainerManager

NewContainerManager creates a new ContainerManager instance

func (*ContainerManager) EnsureImageExists

func (m *ContainerManager) EnsureImageExists(ctx context.Context, imageName string) error

EnsureImageExists checks if an image exists locally and pulls it if it doesn't

func (*ContainerManager) EnsureImageLatest

func (m *ContainerManager) EnsureImageLatest(ctx context.Context, imageName string) error

EnsureImageLatest always pulls the latest version of an image from the registry

func (*ContainerManager) GetContainerLogs

func (m *ContainerManager) GetContainerLogs(ctx context.Context, containerID string, tail int) (string, error)

GetContainerLogs retrieves logs from a container

func (*ContainerManager) ImageExists

func (m *ContainerManager) ImageExists(ctx context.Context, imageName string) (bool, error)

ImageExists checks if a Docker image exists locally

func (*ContainerManager) InspectContainer

func (m *ContainerManager) InspectContainer(ctx context.Context, containerID string) (*ContainerJSON, error)

InspectContainer returns detailed information about a container

func (*ContainerManager) PullImage

func (m *ContainerManager) PullImage(ctx context.Context, imageName string) error

PullImage pulls a Docker image from the registry

func (*ContainerManager) StartContainer

func (m *ContainerManager) StartContainer(ctx context.Context, config ContainerConfig) (*ContainerInfo, error)

StartContainer starts a new container with the given configuration

func (*ContainerManager) StopContainer

func (m *ContainerManager) StopContainer(ctx context.Context, containerID string) error

StopContainer stops a running container

func (*ContainerManager) WaitForHealthy

func (m *ContainerManager) WaitForHealthy(ctx context.Context, containerID string, timeout time.Duration) error

WaitForHealthy waits for a container to become healthy within the specified timeout

type ContainerNetworkSettings

type ContainerNetworkSettings struct {
	Ports map[nat.Port][]nat.PortBinding
}

ContainerNetworkSettings represents network settings

type ContainerState

type ContainerState struct {
	Running bool
	Status  string
	Health  *ContainerHealth
}

ContainerState represents the state of a container

type DockerContainerConfig

type DockerContainerConfig struct {
	Image  string
	Labels map[string]string
}

DockerContainerConfig represents container configuration

type Port

type Port struct {
	PrivatePort int
	PublicPort  string
	Type        string
}

Port represents a port mapping

type VolumeHandler

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

VolumeHandler handles Docker volume operations

func NewVolumeHandler

func NewVolumeHandler(dockerClient client.APIClient, logger logrus.FieldLogger) *VolumeHandler

NewVolumeHandler creates a new VolumeHandler instance

func (*VolumeHandler) DiscoverDataVolumes

func (v *VolumeHandler) DiscoverDataVolumes(ctx context.Context, containerID string) ([]VolumeMount, error)

DiscoverDataVolumes discovers all volume mounts for a given container

func (*VolumeHandler) FilterDataVolumes

func (v *VolumeHandler) FilterDataVolumes(volumes []VolumeMount, dataPathPatterns ...string) []VolumeMount

FilterDataVolumes filters volumes to only include data directories (typically database paths)

func (*VolumeHandler) GetVolumeHostPath

func (v *VolumeHandler) GetVolumeHostPath(ctx context.Context, volumeMount VolumeMount) (string, error)

GetVolumeHostPath returns the host path for a volume mount

func (*VolumeHandler) MountDockerSocket

func (v *VolumeHandler) MountDockerSocket() string

MountDockerSocket returns the Docker socket mount string for external container access

func (*VolumeHandler) PrepareVolumeBinds

func (v *VolumeHandler) PrepareVolumeBinds(volumes []VolumeMount) []string

PrepareVolumeBinds converts VolumeMount structs to Docker bind strings

type VolumeMount

type VolumeMount struct {
	Type        string // bind, volume, tmpfs
	Name        string // volume name (for named volumes)
	Source      string // host path (for bind mounts) or volume name
	Destination string // container path
	Driver      string // volume driver
	Mode        string // rw, ro, z, Z
	RW          bool   // read-write flag
	Propagation string // mount propagation
}

VolumeMount represents a Docker volume mount

Jump to

Keyboard shortcuts

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