Reset the DockerCli and APIClient after loading the environment file
This forces a re-evaluation of the environment variables. Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
parent
a64a5a61a7
commit
86c925fbd3
@ -32,6 +32,8 @@ import (
|
|||||||
dockercli "github.com/docker/cli/cli"
|
dockercli "github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli-plugins/manager"
|
"github.com/docker/cli/cli-plugins/manager"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
"github.com/docker/cli/cli/flags"
|
||||||
|
"github.com/docker/docker/client"
|
||||||
"github.com/morikuni/aec"
|
"github.com/morikuni/aec"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -291,6 +293,18 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset DockerCli and APIClient to get possible `DOCKER_HOST` and/or `DOCKER_CONTEXT` loaded from environment file
|
||||||
|
err = dockerCli.Apply(func(cli *command.DockerCli) error {
|
||||||
|
return cli.Initialize(flags.NewClientOptions(),
|
||||||
|
command.WithInitializeClient(func(_ *command.DockerCli) (client.APIClient, error) {
|
||||||
|
return nil, nil
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
parent := cmd.Root()
|
parent := cmd.Root()
|
||||||
if parent != nil {
|
if parent != nil {
|
||||||
parentPrerun := parent.PersistentPreRunE
|
parentPrerun := parent.PersistentPreRunE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user