@@ -21,6 +21,7 @@ import (
2121 "encoding/json"
2222 "errors"
2323 "fmt"
24+ "io"
2425 "os"
2526 "os/signal"
2627 "path/filepath"
@@ -37,6 +38,7 @@ import (
3738 dockercli "github.com/docker/cli/cli"
3839 "github.com/docker/cli/cli-plugins/manager"
3940 "github.com/docker/cli/cli/command"
41+ "github.com/docker/cli/pkg/kvfile"
4042 "github.com/docker/compose/v2/cmd/formatter"
4143 "github.com/docker/compose/v2/internal/desktop"
4244 "github.com/docker/compose/v2/internal/experimental"
@@ -70,6 +72,26 @@ const (
7072 ComposeMenu = "COMPOSE_MENU"
7173)
7274
75+ // rawEnv load a dot env file using docker/cli key=value parser, without attempt to interpolate or evaluate values
76+ func rawEnv (r io.Reader , filename string , lookup func (key string ) (string , bool )) (map [string ]string , error ) {
77+ lines , err := kvfile .ParseFromReader (r , lookup )
78+ if err != nil {
79+ return nil , fmt .Errorf ("failed to parse env_file %s: %w" , filename , err )
80+ }
81+ vars := types.Mapping {}
82+ for _ , line := range lines {
83+ key , value , _ := strings .Cut (line , "=" )
84+ vars [key ] = value
85+ }
86+ return vars , nil
87+ }
88+
89+ func init () {
90+ // compose evaluates env file values for interpolation
91+ // `raw` format allows to load env_file with the same parser used by docker run --env-file
92+ dotenv .RegisterFormat ("raw" , rawEnv )
93+ }
94+
7395type Backend interface {
7496 api.Service
7597
0 commit comments