Skip to content

Commit 6fe34c4

Browse files
authored
Merge pull request docker#9745 from ulyssessouza/apply-newly-loaded-envvars
Apply newly loaded envvars to "DockerCli" and "APIClient"
2 parents 10cfd55 + 0b4cb85 commit 6fe34c4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
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

pkg/api/proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"github.com/compose-spec/compose-go/types"
2323
)
2424

25+
var _ Service = &ServiceProxy{}
26+
2527
// ServiceProxy implements Service by delegating to implementation functions. This allows lazy init and per-method overrides
2628
type ServiceProxy struct {
2729
BuildFn func(ctx context.Context, project *types.Project, options BuildOptions) error
@@ -59,8 +61,6 @@ func NewServiceProxy() *ServiceProxy {
5961
// Interceptor allow to customize the compose types.Project before the actual Service method is executed
6062
type Interceptor func(ctx context.Context, project *types.Project)
6163

62-
var _ Service = &ServiceProxy{}
63-
6464
// WithService configure proxy to use specified Service as delegate
6565
func (s *ServiceProxy) WithService(service Service) *ServiceProxy {
6666
s.BuildFn = service.Build

0 commit comments

Comments
 (0)