docker

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetProjectName

func GetProjectName(composePath string) string

GetProjectName extracts the project name from the compose file path Docker Compose uses the directory name as the default project name

func GetProjectNameFromPath

func GetProjectNameFromPath(composePath string) string

GetProjectNameFromPath extracts the project name from a compose file path Docker Compose uses the directory name as the default project name

func IsAvailable

func IsAvailable() bool

IsAvailable checks if Docker is available without returning an error

Types

type Client

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

Client wraps the Docker client for container management

func NewClient

func NewClient() (*Client, error)

NewClient creates a new Docker client

func (*Client) Close

func (c *Client) Close() error

Close closes the Docker client connection

func (*Client) DiscoverContainers

func (c *Client) DiscoverContainers(ctx context.Context, composePath string, serviceNames []string) ([]Container, error)

DiscoverContainers finds running containers for the given compose file

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping verifies connectivity to the Docker daemon

func (*Client) WatchEvents

func (c *Client) WatchEvents(ctx context.Context, projectName string, handler EventHandler) error

WatchEvents watches Docker events and calls handler for container lifecycle events This function blocks until the context is cancelled

type ComposeFile

type ComposeFile struct {
	Version  string                    `yaml:"version"`
	Services map[string]ComposeService `yaml:"services"`
}

ComposeFile represents a parsed docker-compose.yml file

func ParseComposeFile

func ParseComposeFile(path string) (*ComposeFile, error)

ParseComposeFile reads and parses a docker-compose.yml file

func (*ComposeFile) GetServiceNames

func (c *ComposeFile) GetServiceNames() []string

GetServiceNames returns a list of service names from the compose file

type ComposeService

type ComposeService struct {
	Image         string        `yaml:"image"`
	Build         interface{}   `yaml:"build"` // Can be string or object
	ContainerName string        `yaml:"container_name"`
	Environment   interface{}   `yaml:"environment"` // Can be array or map
	Ports         []interface{} `yaml:"ports"`
}

ComposeService represents a service definition in docker-compose.yml

type Container

type Container struct {
	ID          string
	Name        string
	ServiceName string
	ProjectName string
	Image       string
	State       string
}

Container represents a discovered Docker container

type ContainerEvent

type ContainerEvent struct {
	Type        string // start, stop, die, restart, kill
	ContainerID string
	Name        string
	Image       string
}

ContainerEvent represents a Docker container lifecycle event

type ContainerStreamer

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

ContainerStreamer streams logs from a Docker container

func NewContainerStreamer

func NewContainerStreamer(client *Client, containerID, name string, handler LineHandler) *ContainerStreamer

NewContainerStreamer creates a new streamer for the given container

func (*ContainerStreamer) Start

func (s *ContainerStreamer) Start() error

Start begins streaming logs from the container

func (*ContainerStreamer) Stop

func (s *ContainerStreamer) Stop() error

Stop stops streaming logs

func (*ContainerStreamer) Wait

func (s *ContainerStreamer) Wait() error

Wait waits for the streaming to complete

type EventHandler

type EventHandler func(event ContainerEvent)

EventHandler is called when a container lifecycle event occurs

type LineHandler

type LineHandler func(source string, line string, timestamp time.Time, isStderr bool)

LineHandler is called for each line of output from a container

Jump to

Keyboard shortcuts

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