MCPcopy
hub / github.com/docker/compose / setEnvWithDotEnv

Function setEnvWithDotEnv

cmd/compose/compose.go:683–719  ·  view source on GitHub ↗
(opts ProjectOptions, dockerCli command.Cli)

Source from the content-addressed store, hash-verified

681}
682
683func setEnvWithDotEnv(opts ProjectOptions, dockerCli command.Cli) error {
684 // Check if we're using a remote config (OCI or Git)
685 // If so, skip env loading as remote loaders haven't been initialized yet
686 // and trying to process the path would fail
687 remoteLoaders := opts.remoteLoaders(dockerCli)
688 for _, path := range opts.ConfigPaths {
689 for _, loader := range remoteLoaders {
690 if loader.Accept(path) {
691 // Remote config - skip env loading for now
692 // It will be loaded later when the project is fully initialized
693 return nil
694 }
695 }
696 }
697
698 options, err := cli.NewProjectOptions(opts.ConfigPaths,
699 cli.WithWorkingDirectory(opts.ProjectDir),
700 cli.WithOsEnv,
701 cli.WithEnvFiles(opts.EnvFiles...),
702 cli.WithDotEnv,
703 )
704 if err != nil {
705 return err
706 }
707 envFromFile, err := dotenv.GetEnvFromFile(composegoutils.GetAsEqualsMap(os.Environ()), options.EnvFiles)
708 if err != nil {
709 return err
710 }
711 for k, v := range envFromFile {
712 if _, ok := os.LookupEnv(k); !ok && strings.HasPrefix(k, "COMPOSE_") {
713 if err := os.Setenv(k, v); err != nil {
714 return err
715 }
716 }
717 }
718 return nil
719}
720
721var printerModes = []string{
722 display.ModeAuto,

Calls 2

remoteLoadersMethod · 0.80
AcceptMethod · 0.45