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
- func GetContainerNumber(log *zerolog.Logger, labels map[string]string) string
- func GetProjectName(log *zerolog.Logger, labels map[string]string) string
- func GetServiceName(log *zerolog.Logger, labels map[string]string) string
- func ParseDependsOnLabel(log *zerolog.Logger, labelValue string) []string
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.