Skip to content

Commit 86c925f

Browse files
committed
Reset the DockerCli and APIClient after loading the environment file
This forces a re-evaluation of the environment variables. Signed-off-by: Ulysses Souza <[email protected]>
1 parent a64a5a6 commit 86c925f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cmd/compose/compose.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
dockercli "github.com/docker/cli/cli"
3333
"github.com/docker/cli/cli-plugins/manager"
3434
"github.com/docker/cli/cli/command"
35+
"github.com/docker/cli/cli/flags"
36+
"github.com/docker/docker/client"
3537
"github.com/morikuni/aec"
3638
"github.com/pkg/errors"
3739
"github.com/sirupsen/logrus"
@@ -291,6 +293,18 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command {
291293
if err != nil {
292294
return err
293295
}
296+
297+
// Reset DockerCli and APIClient to get possible `DOCKER_HOST` and/or `DOCKER_CONTEXT` loaded from environment file
298+
err = dockerCli.Apply(func(cli *command.DockerCli) error {
299+
return cli.Initialize(flags.NewClientOptions(),
300+
command.WithInitializeClient(func(_ *command.DockerCli) (client.APIClient, error) {
301+
return nil, nil
302+
}))
303+
})
304+
if err != nil {
305+
return err
306+
}
307+
294308
parent := cmd.Root()
295309
if parent != nil {
296310
parentPrerun := parent.PersistentPreRunE

0 commit comments

Comments
 (0)