docker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNetworkName    = "doku-network"
	DefaultNetworkSubnet  = "172.20.0.0/16"
	DefaultNetworkGateway = "172.20.0.1"
)

Variables

This section is empty.

Functions

func ApplyResourceLimits

func ApplyResourceLimits(hostConfig *container.HostConfig, config ResourceConfig) error

ApplyResourceLimits applies resource limits to container host config

func BuildImageName

func BuildImageName(repository, tag string) string

BuildImageName constructs a full image name with tag

func ContainerHasLabel

func ContainerHasLabel(labels map[string]string, key, value string) bool

ContainerHasLabel checks if a container has a specific label

func CreateEnvVars

func CreateEnvVars(envMap map[string]string) []string

CreateEnvVars converts a map to Docker environment variable format

func CreatePortBindings

func CreatePortBindings(bindings []PortBinding) nat.PortMap

CreatePortBindings creates Docker port bindings from PortBinding configs

func CreateRestartPolicy

func CreateRestartPolicy(policy string) container.RestartPolicy

CreateRestartPolicy creates a container restart policy

func CreateVolumeMounts

func CreateVolumeMounts(volumes map[string]string) []string

CreateVolumeMounts creates volume mount configuration

func DisableTraefikLabels

func DisableTraefikLabels() map[string]string

DisableTraefikLabels returns labels that disable Traefik for a container

func ExtractInstanceName

func ExtractInstanceName(labels map[string]string) string

ExtractInstanceName extracts the Doku instance name from container labels

func FormatCPUQuota

func FormatCPUQuota(quota, period int64) string

FormatCPUQuota converts Docker CPU quota/period to human-readable cores

func FormatContainerID

func FormatContainerID(id string) string

FormatContainerID shortens a container ID for display

func FormatMemoryBytes

func FormatMemoryBytes(bytes int64) string

FormatMemoryBytes converts bytes to human-readable format

func GenerateContainerName

func GenerateContainerName(instanceName string) string

GenerateContainerName generates a Docker container name with doku prefix

func GenerateDokuManagedLabels

func GenerateDokuManagedLabels(instanceName, serviceType, version string) map[string]string

GenerateDokuManagedLabels generates common labels for Doku-managed containers

func GenerateTCPRouterLabels

func GenerateTCPRouterLabels(config TCPRouterLabels) map[string]string

GenerateTCPRouterLabels generates Traefik TCP router labels

func GenerateTraefikLabels

func GenerateTraefikLabels(config TraefikLabels) map[string]string

GenerateTraefikLabels generates Docker labels for Traefik routing

func GenerateTraefikLabelsForDashboard

func GenerateTraefikLabelsForDashboard(domain string, useTLS bool) map[string]string

GenerateTraefikLabelsForDashboard generates labels for Traefik dashboard

func GenerateTraefikLabelsForService

func GenerateTraefikLabelsForService(instanceName, domain string, port int, useTLS bool) map[string]string

GenerateTraefikLabelsForService generates labels for a standard service

func GenerateVolumeName

func GenerateVolumeName(instanceName, volumeType string) string

GenerateVolumeName generates a Docker volume name

func GetContainerState

func GetContainerState(state string) string

GetContainerState returns a simplified container state

func GetImageRepository

func GetImageRepository(image string) string

GetImageRepository extracts repository from image name e.g., "postgres:14" -> "postgres"

func GetImageTag

func GetImageTag(image string) string

GetImageTag extracts tag from image name e.g., "postgres:14" -> "14"

func IsDokuContainer

func IsDokuContainer(labels map[string]string) bool

IsDokuContainer checks if a container is managed by Doku

func IsHealthy

func IsHealthy(status string) bool

IsHealthy checks if a container is in healthy state

func MergeLabels

func MergeLabels(labelMaps ...map[string]string) map[string]string

MergeLabels merges multiple label maps into one

func NormalizeImageName

func NormalizeImageName(image string) string

NormalizeImageName normalizes an image name e.g., "postgres" -> "postgres:latest", "postgres:14" -> "postgres:14"

func ParseCPUString

func ParseCPUString(cpu string) (quota int64, period int64, err error)

ParseCPUString converts CPU strings like "0.5", "1", "2" to Docker CPU quota and period Docker uses CPUPeriod (default 100000) and CPUQuota to represent CPU limits For example, 0.5 CPUs = CPUQuota 50000 with CPUPeriod 100000

func ParseContainerName

func ParseContainerName(containerName string) string

ParseContainerName extracts instance name from container name e.g., "doku-postgres-14" -> "postgres-14"

func ParseEnvVars

func ParseEnvVars(envVars []string) map[string]string

ParseEnvVars converts Docker environment variable format to map

func ParseMemoryString

func ParseMemoryString(mem string) (int64, error)

ParseMemoryString converts memory strings like "512m", "1g" to bytes

func SanitizeContainerName

func SanitizeContainerName(name string) string

SanitizeContainerName ensures container name is valid

Types

type Client

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

Client wraps the Docker SDK client

func NewClient

func NewClient() (*Client, error)

NewClient creates a new Docker client

func (*Client) Close

func (c *Client) Close() error

Close closes the Docker client connection

func (*Client) ContainerCreate

func (c *Client) ContainerCreate(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (string, error)

ContainerCreate creates a new container

func (*Client) ContainerExists

func (c *Client) ContainerExists(containerName string) (bool, error)

ContainerExists checks if a container exists

func (*Client) ContainerInspect

func (c *Client) ContainerInspect(containerID string) (types.ContainerJSON, error)

ContainerInspect returns detailed information about a container

func (*Client) ContainerList

func (c *Client) ContainerList(all bool) ([]types.Container, error)

ContainerList lists all containers

func (*Client) ContainerLogs

func (c *Client) ContainerLogs(containerID string, follow bool) (io.ReadCloser, error)

ContainerLogs retrieves logs from a container

func (*Client) ContainerRemove

func (c *Client) ContainerRemove(containerID string, force bool) error

ContainerRemove removes a container

func (*Client) ContainerRestart

func (c *Client) ContainerRestart(containerID string, timeout *int) error

ContainerRestart restarts a container

func (*Client) ContainerStart

func (c *Client) ContainerStart(containerID string) error

ContainerStart starts a container

func (*Client) ContainerStats

func (c *Client) ContainerStats(containerID string) (types.ContainerStats, error)

ContainerStats returns resource usage statistics for a container

func (*Client) ContainerStop

func (c *Client) ContainerStop(containerID string, timeout *int) error

ContainerStop stops a container

func (*Client) ImageExists

func (c *Client) ImageExists(imageName string) (bool, error)

ImageExists checks if an image exists locally

func (*Client) ImageList

func (c *Client) ImageList() ([]image.Summary, error)

ImageList lists available images

func (*Client) ImagePull

func (c *Client) ImagePull(imageName string) error

ImagePull pulls an image from a registry

func (*Client) ImageRemove

func (c *Client) ImageRemove(imageID string, force bool) error

ImageRemove removes an image

func (*Client) IsDockerAvailable

func (c *Client) IsDockerAvailable() bool

IsDockerAvailable checks if Docker is available and running

func (*Client) ListContainersByLabel

func (c *Client) ListContainersByLabel(ctx context.Context, labelKey, labelValue string) ([]types.Container, error)

ListContainersByLabel lists containers with a specific label

func (*Client) ListVolumesByLabel

func (c *Client) ListVolumesByLabel(ctx context.Context, labelKey, labelValue string) ([]*volume.Volume, error)

ListVolumesByLabel lists volumes with a specific label

func (*Client) NetworkConnect

func (c *Client) NetworkConnect(networkID, containerID string) error

NetworkConnect connects a container to a network

func (*Client) NetworkCreate

func (c *Client) NetworkCreate(networkName string, options types.NetworkCreate) (string, error)

NetworkCreate creates a new network

func (*Client) NetworkDisconnect

func (c *Client) NetworkDisconnect(networkID, containerID string, force bool) error

NetworkDisconnect disconnects a container from a network

func (*Client) NetworkExists

func (c *Client) NetworkExists(networkName string) (bool, error)

NetworkExists checks if a network exists

func (*Client) NetworkInspect

func (c *Client) NetworkInspect(networkID string) (types.NetworkResource, error)

NetworkInspect returns detailed information about a network

func (*Client) NetworkList

func (c *Client) NetworkList() ([]types.NetworkResource, error)

NetworkList lists all networks

func (*Client) NetworkRemove

func (c *Client) NetworkRemove(networkID string) error

NetworkRemove removes a network

func (*Client) Ping

func (c *Client) Ping() error

Ping checks if Docker daemon is reachable

func (*Client) RemoveContainer

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

RemoveContainer removes a container by name or ID

func (*Client) RemoveNetwork

func (c *Client) RemoveNetwork(ctx context.Context, networkID string) error

RemoveNetwork removes a network by name or ID

func (*Client) RemoveVolume

func (c *Client) RemoveVolume(ctx context.Context, volumeName string) error

RemoveVolume removes a volume by name

func (*Client) StopContainer

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

StopContainer stops a container by name or ID

func (*Client) Version

func (c *Client) Version() (types.Version, error)

Version returns Docker daemon version information

func (*Client) VolumeCreate

func (c *Client) VolumeCreate(volumeName string, labels map[string]string) (*volume.Volume, error)

VolumeCreate creates a new volume

func (*Client) VolumeExists

func (c *Client) VolumeExists(volumeName string) (bool, error)

VolumeExists checks if a volume exists

func (*Client) VolumeInspect

func (c *Client) VolumeInspect(volumeName string) (*volume.Volume, error)

VolumeInspect returns detailed information about a volume

func (*Client) VolumeList

func (c *Client) VolumeList() ([]*volume.Volume, error)

VolumeList lists all volumes

func (*Client) VolumeRemove

func (c *Client) VolumeRemove(volumeName string, force bool) error

VolumeRemove removes a volume

type NetworkManager

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

NetworkManager manages Docker networks for Doku

func NewNetworkManager

func NewNetworkManager(client *Client) *NetworkManager

NewNetworkManager creates a new network manager

func (*NetworkManager) ConnectContainer

func (nm *NetworkManager) ConnectContainer(networkName, containerID string) error

ConnectContainer connects a container to a network

func (*NetworkManager) CreateBridgeNetwork

func (nm *NetworkManager) CreateBridgeNetwork(name, subnet, gateway string) (string, error)

CreateBridgeNetwork creates a bridge network with custom subnet and gateway

func (*NetworkManager) DisconnectContainer

func (nm *NetworkManager) DisconnectContainer(networkName, containerID string, force bool) error

DisconnectContainer disconnects a container from a network

func (*NetworkManager) EnsureDokuNetwork

func (nm *NetworkManager) EnsureDokuNetwork(networkName, subnet, gateway string) error

EnsureDokuNetwork ensures the Doku network exists

func (*NetworkManager) GetConnectedContainers

func (nm *NetworkManager) GetConnectedContainers(networkName string) ([]string, error)

GetConnectedContainers returns a list of containers connected to a network

func (*NetworkManager) GetNetworkByName

func (nm *NetworkManager) GetNetworkByName(name string) (*types.NetworkResource, error)

GetNetworkByName retrieves a network by name

func (*NetworkManager) GetNetworkInfo

func (nm *NetworkManager) GetNetworkInfo(networkName string) (types.NetworkResource, error)

GetNetworkInfo returns information about a network

func (*NetworkManager) IsNetworkHealthy

func (nm *NetworkManager) IsNetworkHealthy(networkName string) (bool, error)

IsNetworkHealthy checks if the network is healthy

func (*NetworkManager) ListDokuNetworks

func (nm *NetworkManager) ListDokuNetworks() ([]types.NetworkResource, error)

ListDokuNetworks lists all networks managed by Doku

func (*NetworkManager) RemoveDokuNetwork

func (nm *NetworkManager) RemoveDokuNetwork(networkName string) error

RemoveDokuNetwork removes the Doku network

type PortBinding

type PortBinding struct {
	ContainerPort int
	HostPort      int
	Protocol      string // "tcp" or "udp"
}

PortBinding creates a port binding configuration

type ResourceConfig

type ResourceConfig struct {
	MemoryLimit   string // e.g., "512m", "1g"
	MemoryReserve string
	CPULimit      string // e.g., "0.5", "1.0", "2"
	CPUReserve    string
}

ResourceConfig holds resource limit configuration

type TCPRouterLabels

type TCPRouterLabels struct {
	Enabled     bool
	RouterName  string
	ServiceName string
	EntryPoint  string
	Port        int
	HostSNI     string // For TLS passthrough
}

TCPRouterLabels generates Traefik labels for TCP routing (for databases, etc.)

type TraefikLabels

type TraefikLabels struct {
	Enabled     bool
	RouterName  string
	ServiceName string
	Subdomain   string
	Domain      string
	Port        int
	EntryPoint  string // "web" for HTTP, "websecure" for HTTPS
	TLS         bool
	Priority    int
	PathPrefix  string
	CustomRules []string
}

TraefikLabels holds Traefik routing configuration

Jump to

Keyboard shortcuts

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