Documentation
¶
Overview ¶
Package docker provides an adapter for the official Docker SDK.
Index ¶
- func EncodeAuthConfig(auth domain.AuthConfig) (string, error)
- func ExtractRegistry(image string) string
- type Client
- func (c *Client) Close() error
- func (c *Client) Containers() ports.ContainerService
- func (c *Client) Events() ports.EventService
- func (c *Client) Exec() ports.ExecService
- func (c *Client) Images() ports.ImageService
- func (c *Client) Networks() ports.NetworkService
- func (c *Client) SDK() *client.Client
- func (c *Client) Services() ports.SwarmService
- func (c *Client) System() ports.SystemService
- type ClientConfig
- type ConfigAuthProvider
- type ContainerServiceAdapter
- func (s *ContainerServiceAdapter) Attach(ctx context.Context, containerID string, opts ports.AttachOptions) (*domain.HijackedResponse, error)
- func (s *ContainerServiceAdapter) CopyLogs(ctx context.Context, containerID string, stdout, stderr io.Writer, ...) error
- func (s *ContainerServiceAdapter) Create(ctx context.Context, config *domain.ContainerConfig) (string, error)
- func (s *ContainerServiceAdapter) Inspect(ctx context.Context, containerID string) (*domain.Container, error)
- func (s *ContainerServiceAdapter) Kill(ctx context.Context, containerID string, signal string) error
- func (s *ContainerServiceAdapter) List(ctx context.Context, opts domain.ListOptions) ([]domain.Container, error)
- func (s *ContainerServiceAdapter) Logs(ctx context.Context, containerID string, opts domain.LogOptions) (io.ReadCloser, error)
- func (s *ContainerServiceAdapter) Pause(ctx context.Context, containerID string) error
- func (s *ContainerServiceAdapter) Remove(ctx context.Context, containerID string, opts domain.RemoveOptions) error
- func (s *ContainerServiceAdapter) Rename(ctx context.Context, containerID string, newName string) error
- func (s *ContainerServiceAdapter) Start(ctx context.Context, containerID string) error
- func (s *ContainerServiceAdapter) Stop(ctx context.Context, containerID string, timeout *time.Duration) error
- func (s *ContainerServiceAdapter) Unpause(ctx context.Context, containerID string) error
- func (s *ContainerServiceAdapter) Wait(ctx context.Context, containerID string) (<-chan domain.WaitResponse, <-chan error)
- type EventServiceAdapter
- type ExecServiceAdapter
- func (s *ExecServiceAdapter) Create(ctx context.Context, containerID string, config *domain.ExecConfig) (string, error)
- func (s *ExecServiceAdapter) Inspect(ctx context.Context, execID string) (*domain.ExecInspect, error)
- func (s *ExecServiceAdapter) Run(ctx context.Context, containerID string, config *domain.ExecConfig, ...) (int, error)
- func (s *ExecServiceAdapter) Start(ctx context.Context, execID string, opts domain.ExecStartOptions) (*domain.HijackedResponse, error)
- type ImageServiceAdapter
- func (s *ImageServiceAdapter) Exists(ctx context.Context, imageRef string) (bool, error)
- func (s *ImageServiceAdapter) Inspect(ctx context.Context, imageID string) (*domain.Image, error)
- func (s *ImageServiceAdapter) List(ctx context.Context, opts domain.ImageListOptions) ([]domain.ImageSummary, error)
- func (s *ImageServiceAdapter) Pull(ctx context.Context, opts domain.PullOptions) (io.ReadCloser, error)
- func (s *ImageServiceAdapter) PullAndWait(ctx context.Context, opts domain.PullOptions) error
- func (s *ImageServiceAdapter) Remove(ctx context.Context, imageID string, force, pruneChildren bool) error
- func (s *ImageServiceAdapter) Tag(ctx context.Context, source, target string) error
- type Logger
- type NetworkServiceAdapter
- func (s *NetworkServiceAdapter) Connect(ctx context.Context, networkID, containerID string, ...) error
- func (s *NetworkServiceAdapter) Create(ctx context.Context, name string, opts ports.NetworkCreateOptions) (string, error)
- func (s *NetworkServiceAdapter) Disconnect(ctx context.Context, networkID, containerID string, force bool) error
- func (s *NetworkServiceAdapter) Inspect(ctx context.Context, networkID string) (*domain.Network, error)
- func (s *NetworkServiceAdapter) List(ctx context.Context, opts domain.NetworkListOptions) ([]domain.Network, error)
- func (s *NetworkServiceAdapter) Remove(ctx context.Context, networkID string) error
- type SwarmServiceAdapter
- func (s *SwarmServiceAdapter) Create(ctx context.Context, spec domain.ServiceSpec, opts domain.ServiceCreateOptions) (string, error)
- func (s *SwarmServiceAdapter) Inspect(ctx context.Context, serviceID string) (*domain.Service, error)
- func (s *SwarmServiceAdapter) List(ctx context.Context, opts domain.ServiceListOptions) ([]domain.Service, error)
- func (s *SwarmServiceAdapter) ListTasks(ctx context.Context, opts domain.TaskListOptions) ([]domain.Task, error)
- func (s *SwarmServiceAdapter) Remove(ctx context.Context, serviceID string) error
- func (s *SwarmServiceAdapter) WaitForServiceTasks(ctx context.Context, serviceID string, timeout time.Duration) ([]domain.Task, error)
- func (s *SwarmServiceAdapter) WaitForTask(ctx context.Context, taskID string, timeout time.Duration) (*domain.Task, error)
- type SystemServiceAdapter
- func (s *SystemServiceAdapter) DiskUsage(ctx context.Context) (*domain.DiskUsage, error)
- func (s *SystemServiceAdapter) Info(ctx context.Context) (*domain.SystemInfo, error)
- func (s *SystemServiceAdapter) Ping(ctx context.Context) (*domain.PingResponse, error)
- func (s *SystemServiceAdapter) Version(ctx context.Context) (*domain.Version, error)
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.
func ExtractRegistry ¶ added in v0.16.0
ExtractRegistry extracts the registry hostname from an image reference. Uses the canonical docker/distribution/reference parser for robustness.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements ports.DockerClient using the official Docker SDK.
func NewClientWithConfig ¶
func NewClientWithConfig(config *ClientConfig) (*Client, error)
NewClientWithConfig creates a new Docker client with custom configuration.
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) 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 ¶
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 ConfigAuthProvider ¶ added in v0.16.0
type ConfigAuthProvider struct {
// contains filtered or unexported fields
}
ConfigAuthProvider implements ports.AuthProvider using Docker's config.json. It reads credentials fresh on each call to support dynamic credential updates (e.g., short-lived tokens from AWS ECR, GCR).
func NewConfigAuthProvider ¶ added in v0.16.0
func NewConfigAuthProvider() *ConfigAuthProvider
NewConfigAuthProvider creates a new auth provider.
func NewConfigAuthProviderWithOptions ¶ added in v0.16.0
func NewConfigAuthProviderWithOptions(configDir string, logger Logger) *ConfigAuthProvider
NewConfigAuthProviderWithOptions creates an auth provider with options.
func (*ConfigAuthProvider) GetAuthConfig ¶ added in v0.16.0
func (p *ConfigAuthProvider) GetAuthConfig(registry string) (domain.AuthConfig, error)
GetAuthConfig returns auth configuration for a registry.
func (*ConfigAuthProvider) GetEncodedAuth ¶ added in v0.16.0
func (p *ConfigAuthProvider) GetEncodedAuth(registry string) (string, error)
GetEncodedAuth returns base64-encoded auth for a registry.
type ContainerServiceAdapter ¶
type ContainerServiceAdapter struct {
// contains filtered or unexported fields
}
ContainerServiceAdapter implements ports.ContainerService using Docker SDK.
func (*ContainerServiceAdapter) Attach ¶
func (s *ContainerServiceAdapter) Attach( ctx context.Context, containerID string, opts ports.AttachOptions, ) (*domain.HijackedResponse, error)
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 ¶
func (s *ContainerServiceAdapter) Create(ctx context.Context, config *domain.ContainerConfig) (string, error)
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 ¶
func (s *ContainerServiceAdapter) List(ctx context.Context, opts domain.ListOptions) ([]domain.Container, error)
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 ¶
func (s *ExecServiceAdapter) Start(ctx context.Context, execID string, opts domain.ExecStartOptions) (*domain.HijackedResponse, error)
Start starts an exec instance.
type ImageServiceAdapter ¶
type ImageServiceAdapter struct {
// contains filtered or unexported fields
}
ImageServiceAdapter implements ports.ImageService using Docker SDK.
func (*ImageServiceAdapter) List ¶
func (s *ImageServiceAdapter) List(ctx context.Context, opts domain.ImageListOptions) ([]domain.ImageSummary, error)
List lists images.
func (*ImageServiceAdapter) Pull ¶
func (s *ImageServiceAdapter) Pull(ctx context.Context, opts domain.PullOptions) (io.ReadCloser, error)
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.
type Logger ¶ added in v0.16.0
type Logger interface {
Debugf(format string, args ...interface{})
Warningf(format string, args ...interface{})
}
Logger interface for auth provider logging
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 ¶
func (s *NetworkServiceAdapter) Create(ctx context.Context, name string, opts ports.NetworkCreateOptions) (string, error)
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 ¶
func (s *NetworkServiceAdapter) List(ctx context.Context, opts domain.NetworkListOptions) ([]domain.Network, error)
List lists networks.
type SwarmServiceAdapter ¶
type SwarmServiceAdapter struct {
// contains filtered or unexported fields
}
SwarmServiceAdapter implements ports.SwarmService using Docker SDK.
func (*SwarmServiceAdapter) Create ¶
func (s *SwarmServiceAdapter) Create(ctx context.Context, spec domain.ServiceSpec, opts domain.ServiceCreateOptions) (string, error)
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 ¶
func (s *SwarmServiceAdapter) List(ctx context.Context, opts domain.ServiceListOptions) ([]domain.Service, error)
List lists services.
func (*SwarmServiceAdapter) ListTasks ¶
func (s *SwarmServiceAdapter) ListTasks(ctx context.Context, opts domain.TaskListOptions) ([]domain.Task, error)
ListTasks lists tasks.
func (*SwarmServiceAdapter) Remove ¶
func (s *SwarmServiceAdapter) Remove(ctx context.Context, serviceID string) error
Remove removes a service.
type SystemServiceAdapter ¶
type SystemServiceAdapter struct {
// contains filtered or unexported fields
}
SystemServiceAdapter implements ports.SystemService using Docker SDK.
func (*SystemServiceAdapter) Info ¶
func (s *SystemServiceAdapter) Info(ctx context.Context) (*domain.SystemInfo, error)
Info returns system information.
func (*SystemServiceAdapter) Ping ¶
func (s *SystemServiceAdapter) Ping(ctx context.Context) (*domain.PingResponse, error)
Ping pings the Docker server.