docker

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 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"

func DeriveProjectNameFromComposeFile added in v0.1.3

func DeriveProjectNameFromComposeFile(composeFilePath string) string

DeriveProjectNameFromComposeFile derives a compose project name from a docker-compose file path. This determines the project name based on where the compose file is located.

For compose file in .devcontainer directory (/foo/bar/.devcontainer/docker-compose.yml):

project name will be "bar_devcontainer"

For compose file in .devcontainer subdirectory (/foo/bar/.devcontainer/app1/docker-compose.yml):

project name will be "app1"

For compose file outside .devcontainer (/foo/bar/docker-compose.yml or /foo/bar/docker/docker-compose.yml):

project name will be the directory name containing the compose file ("bar" or "docker")

func DeriveProjectNameFromComposeFiles added in v0.1.3

func DeriveProjectNameFromComposeFiles(composeFiles []string) string

DeriveProjectNameFromComposeFiles derives a compose project name from a list of compose files. It uses the first file in the list to determine the project name. Returns an empty string if the list is empty or nil.

func DeriveProjectNameFromConfig added in v0.1.3

func DeriveProjectNameFromConfig(cfg Config) string

DeriveProjectNameFromConfig derives a compose project name from a devcontainer config. For compose-based configs, it uses the location of the docker-compose file. For image-based configs, it falls back to the devcontainer.json path.

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 Config added in v0.1.3

type Config interface {
	IsComposeBased() bool
	GetComposeFiles() []string
	GetConfigPath() string
}

Config interface represents the minimal interface needed from devcontainer.Config. This interface avoids a direct import dependency on the devcontainer package.

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