Help us shape the future of Go! Take the 2026 Go Developer Survey

docker

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package docker provides Docker-specific implementation of container runtime, including creating, starting, stopping, and monitoring containers.

Index

Constants

View Source
const (
	// PodmanSocketPath is the default Podman socket path
	PodmanSocketPath = "/var/run/podman/podman.sock"
	// PodmanXDGRuntimeSocketPath is the XDG runtime Podman socket path
	PodmanXDGRuntimeSocketPath = "podman/podman.sock"
	// DockerSocketPath is the default Docker socket path
	DockerSocketPath = "/var/run/docker.sock"
)

Common socket paths

Variables

View Source
var (
	// ErrContainerNotFound is returned when a container is not found
	ErrContainerNotFound = fmt.Errorf("container not found")

	// ErrContainerAlreadyExists is returned when a container already exists
	ErrContainerAlreadyExists = fmt.Errorf("container already exists")

	// ErrContainerNotRunning is returned when a container is not running
	ErrContainerNotRunning = fmt.Errorf("container not running")

	// ErrContainerAlreadyRunning is returned when a container is already running
	ErrContainerAlreadyRunning = fmt.Errorf("container already running")

	// ErrRuntimeNotFound is returned when a container runtime is not found
	ErrRuntimeNotFound = fmt.Errorf("container runtime not found")

	// ErrInvalidRuntimeType is returned when an invalid runtime type is specified
	ErrInvalidRuntimeType = fmt.Errorf("invalid runtime type")

	// ErrAttachFailed is returned when attaching to a container fails
	ErrAttachFailed = fmt.Errorf("failed to attach to container")

	// ErrContainerExited is returned when a container has exited unexpectedly
	ErrContainerExited = fmt.Errorf("container exited unexpectedly")
)

Error types for container operations

Functions

func IsContainerNotFound

func IsContainerNotFound(err error) bool

IsContainerNotFound checks if the error is a container not found error

func NewMonitor

func NewMonitor(rt runtime.Runtime, containerID, containerName string) runtime.Monitor

NewMonitor creates a new container monitor

Types

type Client

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

Client implements the Runtime interface for container operations

func NewClient

func NewClient(ctx context.Context) (*Client, error)

NewClient creates a new container client

func NewClientWithSocketPath

func NewClientWithSocketPath(ctx context.Context, socketPath string, runtimeType runtime.Type) (*Client, error)

NewClientWithSocketPath creates a new container client with a specific socket path

func (*Client) AttachContainer

func (c *Client) AttachContainer(ctx context.Context, containerID string) (io.WriteCloser, io.ReadCloser, error)

AttachContainer attaches to a container

func (*Client) ContainerLogs

func (c *Client) ContainerLogs(ctx context.Context, containerID string) (string, error)

ContainerLogs gets container logs

func (*Client) CreateContainer

func (c *Client) CreateContainer(
	ctx context.Context,
	image, name string,
	command []string,
	envVars, labels map[string]string,
	permissionProfile *permissions.Profile,
	transportType string,
	options *runtime.CreateContainerOptions,
) (string, error)

CreateContainer creates a container without starting it. It configures the container based on the provided permission profile and transport type. If options is nil, default options will be used.

func (*Client) GetContainerInfo

func (c *Client) GetContainerInfo(ctx context.Context, containerID string) (runtime.ContainerInfo, error)

GetContainerInfo gets container information

func (*Client) ImageExists

func (c *Client) ImageExists(ctx context.Context, imageName string) (bool, error)

ImageExists checks if an image exists locally

func (*Client) IsContainerRunning

func (c *Client) IsContainerRunning(ctx context.Context, containerID string) (bool, error)

IsContainerRunning checks if a container is running

func (*Client) ListContainers

func (c *Client) ListContainers(ctx context.Context) ([]runtime.ContainerInfo, error)

ListContainers lists containers

func (*Client) PullImage

func (c *Client) PullImage(ctx context.Context, imageName string) error

PullImage pulls an image from a registry

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(ctx context.Context, containerID string) error

RemoveContainer removes a container If the container doesn't exist, it returns success

func (*Client) StartContainer

func (c *Client) StartContainer(ctx context.Context, containerID string) error

StartContainer starts a container If the container is already running, it returns success

func (*Client) StopContainer

func (c *Client) StopContainer(ctx context.Context, containerID string) error

StopContainer stops a container If the container is already stopped, it returns success

type ContainerError

type ContainerError struct {
	// Err is the underlying error
	Err error
	// ContainerID is the ID of the container
	ContainerID string
	// Message is an optional error message
	Message string
}

ContainerError represents an error related to container operations

func NewContainerError

func NewContainerError(err error, containerID, message string) *ContainerError

NewContainerError creates a new container error

func (*ContainerError) Error

func (e *ContainerError) Error() string

Error returns the error message

func (*ContainerError) Unwrap

func (e *ContainerError) Unwrap() error

Unwrap returns the underlying error

type ContainerMonitor

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

ContainerMonitor watches a container's state and reports when it exits

func (*ContainerMonitor) StartMonitoring

func (m *ContainerMonitor) StartMonitoring(ctx context.Context) (<-chan error, error)

StartMonitoring starts monitoring the container

func (*ContainerMonitor) StopMonitoring

func (m *ContainerMonitor) StopMonitoring()

StopMonitoring stops monitoring the container

Jump to

Keyboard shortcuts

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