docker

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveDevcontainerProjectName

func DeriveDevcontainerProjectName(configPath string) string

DeriveDevcontainerProjectName derives a compose project name from a devcontainer.json path. This follows the devcontainer naming convention.

For standard layout (/foo/bar/.devcontainer/devcontainer.json):

project name will be "bar_devcontainer"

For multi-config layout (/foo/bar/.devcontainer/app1/devcontainer.json):

project name will be "app1"

Types

type ComposeClient

type ComposeClient interface {
	ContainerClient
	NetworkList(ctx context.Context, options NetworkListOptions) ([]NetworkInfo, error)
	NetworkRemove(ctx context.Context, networkID string) error
	VolumeList(ctx context.Context, options VolumeListOptions) ([]VolumeInfo, error)
	VolumeRemove(ctx context.Context, volumeName string, force bool) error
}

ComposeClient extends ContainerClient with network and volume operations.

type ComposeOps

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

ComposeOps provides operations on Docker Compose projects.

func NewComposeOps

func NewComposeOps(client ComposeClient) *ComposeOps

NewComposeOps creates a new ComposeOps with the given client.

func (*ComposeOps) DownComposeProject

func (c *ComposeOps) DownComposeProject(ctx context.Context, projectName string, removeVolumes bool) error

DownComposeProject stops and removes containers and networks for a compose project.

func (*ComposeOps) FindComposeContainers

func (c *ComposeOps) FindComposeContainers(ctx context.Context, projectName string) ([]ContainerInfo, error)

FindComposeContainers finds containers belonging to a compose project.

func (*ComposeOps) StopComposeProject

func (c *ComposeOps) StopComposeProject(ctx context.Context, projectName string) error

StopComposeProject stops all containers in a compose project.

type ContainerClient

type ContainerClient interface {
	ContainerList(ctx context.Context, options ContainerListOptions) ([]ContainerInfo, error)
	ContainerStop(ctx context.Context, containerID string, timeout *int) error
	ContainerRemove(ctx context.Context, containerID string, force bool) error
	Close() error
}

ContainerClient is an interface for Docker container operations. This interface allows for easy mocking in tests.

type ContainerInfo

type ContainerInfo struct {
	ID     string
	Names  []string
	Labels map[string]string
	State  string
}

ContainerInfo represents container information.

type ContainerListOptions

type ContainerListOptions struct {
	All         bool
	LabelFilter string
}

ContainerListOptions represents options for listing containers.

type ContainerOps

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

ContainerOps provides operations on containers.

func NewContainerOps

func NewContainerOps(client ContainerClient) *ContainerOps

NewContainerOps creates a new ContainerOps with the given client.

func (*ContainerOps) FindDevcontainersByConfigPath

func (c *ContainerOps) FindDevcontainersByConfigPath(ctx context.Context, configPath string) ([]ContainerInfo, error)

FindDevcontainersByConfigPath finds devcontainers by the config file path.

func (*ContainerOps) FindDevcontainersByFolder

func (c *ContainerOps) FindDevcontainersByFolder(ctx context.Context, folderPath string) ([]ContainerInfo, error)

FindDevcontainersByFolder finds devcontainers by the local folder path.

func (*ContainerOps) RemoveContainers

func (c *ContainerOps) RemoveContainers(ctx context.Context, containers []ContainerInfo) error

RemoveContainers removes the specified containers.

func (*ContainerOps) StopContainers

func (c *ContainerOps) StopContainers(ctx context.Context, containers []ContainerInfo) error

StopContainers stops the specified containers.

type NetworkInfo

type NetworkInfo struct {
	ID   string
	Name string
}

NetworkInfo represents network information.

type NetworkListOptions

type NetworkListOptions struct {
	LabelFilter string
}

NetworkListOptions represents options for listing networks.

type RealDockerClient

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

RealDockerClient wraps the Docker SDK client to implement ContainerClient interface.

func NewClient

func NewClient() (*RealDockerClient, error)

NewClient creates a new Docker client using default context.

func NewClientWithContext

func NewClientWithContext(contextName string) (*RealDockerClient, error)

NewClientWithContext creates a new Docker client with the specified context. If contextName is empty, it uses the current context from Docker config.

func (*RealDockerClient) Close

func (c *RealDockerClient) Close() error

Close closes the Docker client.

func (*RealDockerClient) ContainerList

func (c *RealDockerClient) ContainerList(ctx context.Context, options ContainerListOptions) ([]ContainerInfo, error)

ContainerList lists containers matching the given options.

func (*RealDockerClient) ContainerRemove

func (c *RealDockerClient) ContainerRemove(ctx context.Context, containerID string, force bool) error

ContainerRemove removes a container.

func (*RealDockerClient) ContainerStop

func (c *RealDockerClient) ContainerStop(ctx context.Context, containerID string, timeout *int) error

ContainerStop stops a container.

func (*RealDockerClient) NetworkList

func (c *RealDockerClient) NetworkList(ctx context.Context, options NetworkListOptions) ([]NetworkInfo, error)

NetworkList lists networks matching the given options.

func (*RealDockerClient) NetworkRemove

func (c *RealDockerClient) NetworkRemove(ctx context.Context, networkID string) error

NetworkRemove removes a network.

func (*RealDockerClient) VolumeList

func (c *RealDockerClient) VolumeList(ctx context.Context, options VolumeListOptions) ([]VolumeInfo, error)

VolumeList lists volumes matching the given options.

func (*RealDockerClient) VolumeRemove

func (c *RealDockerClient) VolumeRemove(ctx context.Context, volumeName string, force bool) error

VolumeRemove removes a volume.

type VolumeInfo

type VolumeInfo struct {
	Name   string
	Labels map[string]string
}

VolumeInfo represents volume information.

type VolumeListOptions

type VolumeListOptions struct {
	LabelFilter string
}

VolumeListOptions represents options for listing volumes.

Jump to

Keyboard shortcuts

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