docker

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package docker provides an adapter for the official Docker SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeAuthConfig

func EncodeAuthConfig(auth domain.AuthConfig) (string, error)

EncodeAuthConfig encodes an auth config for use in API calls.

Types

type Client

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

Client implements ports.DockerClient using the official Docker SDK.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new Docker client from environment variables.

func NewClientWithConfig

func NewClientWithConfig(config *ClientConfig) (*Client, error)

NewClientWithConfig creates a new Docker client with custom configuration.

func (*Client) Close

func (c *Client) Close() error

Close closes the client.

func (*Client) Containers

func (c *Client) Containers() ports.ContainerService

Containers returns the container service.

func (*Client) Events

func (c *Client) Events() ports.EventService

Events returns the event service.

func (*Client) Exec

func (c *Client) Exec() ports.ExecService

Exec returns the exec service.

func (*Client) Images

func (c *Client) Images() ports.ImageService

Images returns the image service.

func (*Client) Networks

func (c *Client) Networks() ports.NetworkService

Networks returns the network service.

func (*Client) SDK

func (c *Client) SDK() *client.Client

SDK returns the underlying Docker SDK client. This should only be used for operations not covered by the ports interface.

func (*Client) Services

func (c *Client) Services() ports.SwarmService

Services returns the Swarm service.

func (*Client) System

func (c *Client) System() ports.SystemService

System returns the system service.

type ClientConfig

type ClientConfig struct {
	// Host is the Docker host address (e.g., "unix:///var/run/docker.sock")
	Host string

	// Version is the API version (empty for auto-negotiation)
	Version string

	// HTTPClient is a custom HTTP client (optional)
	HTTPClient *http.Client

	// HTTPHeaders are custom HTTP headers (optional)
	HTTPHeaders map[string]string

	// Connection pool settings
	MaxIdleConns        int
	MaxIdleConnsPerHost int
	MaxConnsPerHost     int
	IdleConnTimeout     time.Duration

	// Timeout settings
	DialTimeout           time.Duration
	ResponseHeaderTimeout time.Duration
}

ClientConfig contains configuration for the Docker client.

func DefaultConfig

func DefaultConfig() *ClientConfig

DefaultConfig returns a default configuration.

type ContainerServiceAdapter

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

ContainerServiceAdapter implements ports.ContainerService using Docker SDK.

func (*ContainerServiceAdapter) Attach

Attach attaches to a container.

func (*ContainerServiceAdapter) CopyLogs

func (s *ContainerServiceAdapter) CopyLogs(
	ctx context.Context, containerID string, stdout, stderr io.Writer, opts domain.LogOptions,
) error

CopyLogs copies container logs to writers.

func (*ContainerServiceAdapter) Create

Create creates a new container.

func (*ContainerServiceAdapter) Inspect

func (s *ContainerServiceAdapter) Inspect(ctx context.Context, containerID string) (*domain.Container, error)

Inspect returns container information.

func (*ContainerServiceAdapter) Kill

func (s *ContainerServiceAdapter) Kill(ctx context.Context, containerID string, signal string) error

Kill sends a signal to a container.

func (*ContainerServiceAdapter) List

List lists containers.

func (*ContainerServiceAdapter) Logs

func (s *ContainerServiceAdapter) Logs(ctx context.Context, containerID string, opts domain.LogOptions) (io.ReadCloser, error)

Logs returns container logs.

func (*ContainerServiceAdapter) Pause

func (s *ContainerServiceAdapter) Pause(ctx context.Context, containerID string) error

Pause pauses a container.

func (*ContainerServiceAdapter) Remove

func (s *ContainerServiceAdapter) Remove(ctx context.Context, containerID string, opts domain.RemoveOptions) error

Remove removes a container.

func (*ContainerServiceAdapter) Rename

func (s *ContainerServiceAdapter) Rename(ctx context.Context, containerID string, newName string) error

Rename renames a container.

func (*ContainerServiceAdapter) Start

func (s *ContainerServiceAdapter) Start(ctx context.Context, containerID string) error

Start starts a container.

func (*ContainerServiceAdapter) Stop

func (s *ContainerServiceAdapter) Stop(ctx context.Context, containerID string, timeout *time.Duration) error

Stop stops a container.

func (*ContainerServiceAdapter) Unpause

func (s *ContainerServiceAdapter) Unpause(ctx context.Context, containerID string) error

Unpause unpauses a container.

func (*ContainerServiceAdapter) Wait

func (s *ContainerServiceAdapter) Wait(ctx context.Context, containerID string) (<-chan domain.WaitResponse, <-chan error)

Wait waits for a container to stop.

type EventServiceAdapter

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

EventServiceAdapter implements ports.EventService using Docker SDK. This implementation uses context-based cancellation for safe channel management.

func (*EventServiceAdapter) Subscribe

func (s *EventServiceAdapter) Subscribe(ctx context.Context, filter domain.EventFilter) (<-chan domain.Event, <-chan error)

Subscribe subscribes to Docker events. The returned channels are closed when the context is canceled or an error occurs. The caller should NOT close these channels.

func (*EventServiceAdapter) SubscribeWithCallback

func (s *EventServiceAdapter) SubscribeWithCallback(
	ctx context.Context,
	filter domain.EventFilter,
	callback ports.EventCallback,
) error

SubscribeWithCallback subscribes to events with a callback.

type ExecServiceAdapter

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

ExecServiceAdapter implements ports.ExecService using Docker SDK.

func (*ExecServiceAdapter) Create

func (s *ExecServiceAdapter) Create(ctx context.Context, containerID string, config *domain.ExecConfig) (string, error)

Create creates an exec instance.

func (*ExecServiceAdapter) Inspect

func (s *ExecServiceAdapter) Inspect(ctx context.Context, execID string) (*domain.ExecInspect, error)

Inspect returns exec information.

func (*ExecServiceAdapter) Run

func (s *ExecServiceAdapter) Run(
	ctx context.Context, containerID string, config *domain.ExecConfig, stdout, stderr io.Writer,
) (int, error)

Run executes a command in a container and waits for it to complete.

func (*ExecServiceAdapter) Start

Start starts an exec instance.

type ImageServiceAdapter

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

ImageServiceAdapter implements ports.ImageService using Docker SDK.

func (*ImageServiceAdapter) Exists

func (s *ImageServiceAdapter) Exists(ctx context.Context, imageRef string) (bool, error)

Exists checks if an image exists locally.

func (*ImageServiceAdapter) Inspect

func (s *ImageServiceAdapter) Inspect(ctx context.Context, imageID string) (*domain.Image, error)

Inspect returns image information.

func (*ImageServiceAdapter) List

List lists images.

func (*ImageServiceAdapter) Pull

Pull pulls an image from a registry.

func (*ImageServiceAdapter) PullAndWait

func (s *ImageServiceAdapter) PullAndWait(ctx context.Context, opts domain.PullOptions) error

PullAndWait pulls an image and waits for completion.

func (*ImageServiceAdapter) Remove

func (s *ImageServiceAdapter) Remove(ctx context.Context, imageID string, force, pruneChildren bool) error

Remove removes an image.

func (*ImageServiceAdapter) Tag

func (s *ImageServiceAdapter) Tag(ctx context.Context, source, target string) error

Tag tags an image.

type NetworkServiceAdapter

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

NetworkServiceAdapter implements ports.NetworkService using Docker SDK.

func (*NetworkServiceAdapter) Connect

func (s *NetworkServiceAdapter) Connect(ctx context.Context, networkID, containerID string, config *domain.EndpointSettings) error

Connect connects a container to a network.

func (*NetworkServiceAdapter) Create

Create creates a network.

func (*NetworkServiceAdapter) Disconnect

func (s *NetworkServiceAdapter) Disconnect(ctx context.Context, networkID, containerID string, force bool) error

Disconnect disconnects a container from a network.

func (*NetworkServiceAdapter) Inspect

func (s *NetworkServiceAdapter) Inspect(ctx context.Context, networkID string) (*domain.Network, error)

Inspect returns network information.

func (*NetworkServiceAdapter) List

List lists networks.

func (*NetworkServiceAdapter) Remove

func (s *NetworkServiceAdapter) Remove(ctx context.Context, networkID string) error

Remove removes a network.

type SwarmServiceAdapter

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

SwarmServiceAdapter implements ports.SwarmService using Docker SDK.

func (*SwarmServiceAdapter) Create

Create creates a new Swarm service.

func (*SwarmServiceAdapter) Inspect

func (s *SwarmServiceAdapter) Inspect(ctx context.Context, serviceID string) (*domain.Service, error)

Inspect returns service information.

func (*SwarmServiceAdapter) List

List lists services.

func (*SwarmServiceAdapter) ListTasks

ListTasks lists tasks.

func (*SwarmServiceAdapter) Remove

func (s *SwarmServiceAdapter) Remove(ctx context.Context, serviceID string) error

Remove removes a service.

func (*SwarmServiceAdapter) WaitForServiceTasks

func (s *SwarmServiceAdapter) WaitForServiceTasks(ctx context.Context, serviceID string, timeout time.Duration) ([]domain.Task, error)

WaitForServiceTasks waits for all service tasks to reach a terminal state.

func (*SwarmServiceAdapter) WaitForTask

func (s *SwarmServiceAdapter) WaitForTask(ctx context.Context, taskID string, timeout time.Duration) (*domain.Task, error)

WaitForTask waits for a task to reach a terminal state.

type SystemServiceAdapter

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

SystemServiceAdapter implements ports.SystemService using Docker SDK.

func (*SystemServiceAdapter) DiskUsage

func (s *SystemServiceAdapter) DiskUsage(ctx context.Context) (*domain.DiskUsage, error)

DiskUsage returns disk usage information.

func (*SystemServiceAdapter) Info

Info returns system information.

func (*SystemServiceAdapter) Ping

Ping pings the Docker server.

func (*SystemServiceAdapter) Version

Version returns version information.

Jump to

Keyboard shortcuts

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