Reference library for parsing and loading Compose YAML files https://compose-spec.io
  • Go 99.7%
  • Makefile 0.2%
Find a file
Nicolas De Loof 3423c00629 loader: tell a consistency error is invalid for every check
Several checks of checkConsistency returned their error bare, so
errors.Is(err, errdefs.ErrInvalid) held for most inconsistencies of a
project but not for an additional context on an unknown or non-buildable
service, a healthcheck test with an unknown keyword, a network_mode on an
unknown or disabled service, a negative scale or replicas count, or a target
mounted twice. They now wrap ErrInvalid like the others, which appends
"invalid compose project" to their message, and the misspelt "mutualy" of
the dockerfile and dockerfile_inline conflict is fixed.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
History 2026-11-16 17:38:27 +01:00
.github
ci
cli
cmd
consts
dotenv
errdefs
format
graph
internal/generate/containerspec
interpolation
loader
override
paths
schema
scripts/validate/template
template
transform
tree
types
utils
validation
.gitattributes
.gitignore
.golangci.yml
.pre-commit-config.yaml
AGENTS.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
go.mod
go.sum
LICENSE
MAINTENANCE.md
Makefile template: fuzz Substitute and ExtractVariables 2026-10-23 16:00:08 +02:00
NOTICE Add NOTICE file 2020-06-22 11:46:47 +02:00
package.go
parsing.md
README.md
TESTING.md

compose-go

Continuous integration Go Reference

Go reference library for parsing and loading Compose files as specified by the Compose specification.

Usage

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/compose-spec/compose-go/v2/cli"
)

func main() {
	composeFilePath := "docker-compose.yml"
	projectName := "my_project"
	ctx := context.Background()

	options, err := cli.NewProjectOptions(
		[]string{composeFilePath},
		cli.WithOsEnv,
		cli.WithDotEnv,
		cli.WithName(projectName),
	)
	if err != nil {
		log.Fatal(err)
	}

	project, err := options.LoadProject(ctx)
	if err != nil {
		log.Fatal(err)
	}

	// Use the MarshalYAML method to get YAML representation
	projectYAML, err := project.MarshalYAML()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(projectYAML))
}

Build the library

To build the library, you could either use the makefile

make build

or use the go build command

go build ./...

Run the tests

You can run the tests with the makefile

make test

or with the go test command

gotestsum ./...

Other helpful make commands

Run the linter

make lint

Check the license headers

make check-license

Used by