compose

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package compose provides functionality for handling Docker Compose-specific logic, including parsing depends_on labels and extracting service names for dependency management.

Key components:

  • ParseDependsOnLabel: Parses the Docker Compose depends_on label value, expecting a comma-separated list of service[:condition[:required]] format, returns a slice of service names.
  • GetServiceName: Extracts the service name from Docker Compose labels using the com.docker.compose.service label.

Usage example:

// Callers must provide a non-nil *zerolog.Logger (process logger).
labels := map[string]string{
	"com.docker.compose.service": "myservice",
}
services := compose.ParseDependsOnLabel(log, "postgres:service_started:required,redis")
serviceName := compose.GetServiceName(log, labels)

Index

Constants

View Source
const (
	// ComposeDependsOnLabel lists container names this container depends on from Docker Compose, comma-separated.
	ComposeDependsOnLabel = "com.docker.compose.depends_on"
	// ComposeProjectLabel specifies the project name of the container in Docker Compose.
	ComposeProjectLabel = "com.docker.compose.project"
	// ComposeServiceLabel specifies the service name of the container in Docker Compose.
	ComposeServiceLabel = "com.docker.compose.service"
	// ComposeContainerNumber specifies the container number of the container in Docker Compose.
	ComposeContainerNumber = "com.docker.compose.container-number"
)

Docker Compose labels.

Variables

This section is empty.

Functions

func GetContainerNumber

func GetContainerNumber(log *zerolog.Logger, labels map[string]string) string

GetContainerNumber extracts the container number from the Docker Compose labels.

If the ComposeContainerNumber label is present, returns its value. Otherwise, returns an empty string.

Parameters:

  • labels: Map of container labels.

Returns:

  • string: Container replica number if present, empty string otherwise.

func GetProjectName

func GetProjectName(log *zerolog.Logger, labels map[string]string) string

GetProjectName extracts the project name from Docker Compose labels.

If the com.docker.compose.project label is present, returns its value. Otherwise, returns an empty string.

Parameters:

  • labels: Map of container labels.

Returns:

  • string: Project name if present, empty string otherwise.

func GetServiceName

func GetServiceName(log *zerolog.Logger, labels map[string]string) string

GetServiceName extracts the service name from Docker Compose labels.

If the com.docker.compose.service label is present, returns its value. Otherwise, returns an empty string.

Parameters:

  • labels: Map of container labels.

Returns:

  • string: Service name if present, empty string otherwise.

func ParseDependsOnLabel

func ParseDependsOnLabel(log *zerolog.Logger, labelValue string) []string

ParseDependsOnLabel parses the Docker Compose depends_on label value.

It handles both JSON format (Docker Compose v2+) and comma-separated string format. Returns a slice of service names.

Parameters:

  • labelValue: The raw label value from com.docker.compose.depends_on.

Returns:

  • []string: List of service names.

Types

This section is empty.

Jump to

Keyboard shortcuts

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