docker

package
v0.0.0-...-ebe201a Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilOption              = errors.New("nil option provided to client configuration")
	ErrInvalidHost            = errors.New("invalid Docker host specification")
	ErrMissingTLSConfig       = errors.New("TLS verification enabled but certificate paths not provided")
	ErrInvalidTLSCert         = errors.New("invalid or inaccessible TLS certificate")
	ErrInvalidTLSKey          = errors.New("invalid or inaccessible TLS key")
	ErrInvalidTLSCA           = errors.New("invalid or inaccessible TLS CA certificate")
	ErrConnectionFailed       = errors.New("failed to connect to Docker daemon")
	ErrClientNotInitialized   = errors.New("Docker client not initialized")
	ErrClientClosed           = errors.New("Docker client manager has been closed")
	ErrInvalidAPIVersion      = errors.New("invalid Docker API version format")
	ErrContextCanceled        = errors.New("context was canceled while operating Docker client")
	ErrEmptyOption            = errors.New("empty value provided for required option")
	ErrTLSConfigValidation    = errors.New("TLS configuration validation failed")
	ErrCertificateExpired     = errors.New("TLS certificate has expired")
	ErrCertificateNotYetValid = errors.New("TLS certificate is not yet valid")
)

Common errors with detailed descriptions for better error handling.

Functions

func GetDefaultClient

func GetDefaultClient() (client.APIClient, error)

GetDefaultClient returns a client from the default manager.

func GetDefaultClientWithContext

func GetDefaultClientWithContext(ctx context.Context) (client.APIClient, error)

GetDefaultClientWithContext returns a client from the default manager with context.

func NewBackendService

func NewBackendService(manager Manager, logger logger.Logger) compute.BackendService

NewBackendService creates a new Docker backend service.

func SetDefaultManager

func SetDefaultManager(m Manager)

SetDefaultManager sets the default manager instance.

Types

type BackendService

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

BackendService implements the compute.BackendService interface for Docker.

func (*BackendService) Create

Create creates a new Docker container.

func (*BackendService) Delete

func (s *BackendService) Delete(ctx context.Context, id string, force bool) error

Delete removes a Docker container.

func (*BackendService) Get

Get retrieves a Docker container by ID.

func (*BackendService) GetBackendInfo

func (s *BackendService) GetBackendInfo(ctx context.Context) (*compute.BackendInfo, error)

GetBackendInfo returns information about the Docker backend.

func (*BackendService) GetBackendType

func (s *BackendService) GetBackendType() compute.ComputeBackend

GetBackendType returns the backend type.

func (*BackendService) GetResourceUsage

func (s *BackendService) GetResourceUsage(ctx context.Context, id string) (*compute.ResourceUsage, error)

GetResourceUsage gets current resource usage for a container.

func (*BackendService) GetSupportedInstanceTypes

func (s *BackendService) GetSupportedInstanceTypes() []compute.ComputeInstanceType

GetSupportedInstanceTypes returns supported instance types.

func (*BackendService) List

List retrieves Docker containers based on options.

func (*BackendService) Pause

func (s *BackendService) Pause(ctx context.Context, id string) error

Pause pauses a Docker container.

func (*BackendService) Restart

func (s *BackendService) Restart(ctx context.Context, id string, force bool) error

Restart restarts a Docker container.

func (*BackendService) Start

func (s *BackendService) Start(ctx context.Context, id string) error

Start starts a Docker container.

func (*BackendService) Stop

func (s *BackendService) Stop(ctx context.Context, id string, force bool) error

Stop stops a Docker container.

func (*BackendService) Unpause

func (s *BackendService) Unpause(ctx context.Context, id string) error

Unpause unpauses a Docker container.

func (*BackendService) Update

Update updates a Docker container.

func (*BackendService) UpdateResourceLimits

func (s *BackendService) UpdateResourceLimits(ctx context.Context, id string, resources compute.ComputeResources) error

UpdateResourceLimits updates resource limits for a container.

func (*BackendService) ValidateConfig

func (s *BackendService) ValidateConfig(ctx context.Context, config compute.ComputeInstanceConfig) error

ValidateConfig validates a compute instance configuration for Docker.

type ClientConfig

type ClientConfig struct {
	Logger                      logger.Logger
	Headers                     map[string]string
	DialContext                 func(ctx context.Context, network, addr string) (net.Conn, error)
	Host                        string
	APIVersion                  string
	TLSCertPath                 string
	TLSKeyPath                  string
	TLSCAPath                   string
	TLSCipherSuites             []uint16
	KeepAlive                   time.Duration
	MaxIdleConns                int
	TLSHandshakeTimeout         time.Duration
	ConnectionTimeout           time.Duration
	IdleConnTimeout             time.Duration
	ResponseHeaderTimeout       time.Duration
	ExpectContinueTimeout       time.Duration
	PingTimeout                 time.Duration
	RetryDelay                  time.Duration
	ConnectionIdleTimeout       time.Duration
	MaxIdleConnsPerHost         int
	MaxConnsPerHost             int
	RetryCount                  int
	RequestTimeout              time.Duration
	TLSMinVersion               uint16
	TLSMaxVersion               uint16
	TLSVerify                   bool
	TLSPreferServerCipherSuites bool
}

ClientConfig represents the configuration for the Docker client.

func DefaultClientConfig

func DefaultClientConfig() ClientConfig

DefaultClientConfig returns the default client configuration.

type ClientManager

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

ClientManager manages Docker clients.

func NewManager

func NewManager(opts ...ClientOption) (*ClientManager, error)

NewManager creates a new Docker client manager.

func (*ClientManager) Close

func (m *ClientManager) Close() error

Close closes the managed Docker client.

func (*ClientManager) GetClient

func (m *ClientManager) GetClient() (client.APIClient, error)

GetClient returns a thread-safe Docker API client wrapper.

func (*ClientManager) GetConfig

func (m *ClientManager) GetConfig() ClientConfig

GetConfig returns a copy of the current client configuration.

func (*ClientManager) GetWithContext

func (m *ClientManager) GetWithContext(ctx context.Context) (client.APIClient, error)

GetWithContext returns a thread-safe Docker API client wrapper with context.

func (*ClientManager) IsClosed

func (m *ClientManager) IsClosed() bool

IsClosed checks if the client manager has been closed.

func (*ClientManager) IsInitialized

func (m *ClientManager) IsInitialized() bool

IsInitialized checks if the client manager has successfully initialized.

func (*ClientManager) Ping

func (m *ClientManager) Ping(ctx context.Context) (types.Ping, error)

Ping checks the connectivity with the Docker daemon.

type ClientOption

type ClientOption func(*ClientConfig) error

ClientOption represents a functional option for configuring the Docker client.

func WithAPIVersion

func WithAPIVersion(version string) ClientOption

WithAPIVersion sets the Docker API version.

func WithHost

func WithHost(host string) ClientOption

WithHost sets the Docker daemon host.

func WithLogger

func WithLogger(logger logger.Logger) ClientOption

WithLogger sets the logger.

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) ClientOption

WithRequestTimeout sets the request timeout.

func WithRetry

func WithRetry(count int, delay time.Duration) ClientOption

WithRetry sets retry parameters.

func WithTLSConfig

func WithTLSConfig(certPath, keyPath, caPath string) ClientOption

WithTLSConfig sets the complete TLS configuration.

func WithTLSVerify

func WithTLSVerify(verify bool) ClientOption

WithTLSVerify enables TLS verification.

type Manager

type Manager interface {
	// GetClient returns a thread-safe Docker API client wrapper
	GetClient() (client.APIClient, error)

	// GetWithContext returns a thread-safe Docker API client wrapper with the specified context
	GetWithContext(ctx context.Context) (client.APIClient, error)

	// Ping checks the connectivity with the Docker daemon
	Ping(ctx context.Context) (types.Ping, error)

	// Close closes all clients and releases resources
	Close() error

	// IsInitialized checks if the client is initialized
	IsInitialized() bool

	// IsClosed checks if the client is closed
	IsClosed() bool

	// GetConfig returns the client configuration
	GetConfig() ClientConfig
}

Manager is the interface for Docker client operations.

func DefaultManager

func DefaultManager() Manager

DefaultManager returns the singleton manager instance.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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