Reference library for parsing and loading Compose YAML files
See the codeGo reference library for parsing and loading Compose files as specified by the Compose specification.
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))
}
To build the library, you could either use the makefile
make build
or use the go build command
go build ./...
You can run the tests with the makefile
make test
or with the go test command
gotestsum ./...
Run the linter
make lint
Check the license headers
make check_license
Check the compose-spec.json file is sync with the compose-spec repository
make check_compose_spec
289 followers · starred Dec 2022
98 followers · starred Mar 2023
32 followers · starred Jun 2025
5,125 followers · starred Jun 2022
Reference library for parsing and loading Compose YAML files
See the codeGo reference library for parsing and loading Compose files as specified by the Compose specification.
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))
}
To build the library, you could either use the makefile
make build
or use the go build command
go build ./...
You can run the tests with the makefile
make test
or with the go test command
gotestsum ./...
Run the linter
make lint
Check the license headers
make check_license
Check the compose-spec.json file is sync with the compose-spec repository
make check_compose_spec
289 followers · starred Dec 2022
98 followers · starred Mar 2023
32 followers · starred Jun 2025
5,125 followers · starred Jun 2022