Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 04c3833

Browse files
committed
define exec env by merging service env with command line --env
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent dbd936b commit 04c3833

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

local/compose/exec.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,18 @@ func (s *composeService) Exec(ctx context.Context, project *types.Project, opts
4949
}
5050
container := containers[0]
5151

52+
var env []string
53+
projectEnv := types.NewMappingWithEquals(opts.Environment).Resolve(func(s string) (string, bool) {
54+
v, ok := project.Environment[s]
55+
return v, ok
56+
})
57+
for k, v := range service.Environment.OverrideBy(projectEnv) {
58+
env = append(env, fmt.Sprintf("%s=%s", k, *v))
59+
}
60+
5261
exec, err := s.apiClient.ContainerExecCreate(ctx, container.ID, apitypes.ExecConfig{
5362
Cmd: opts.Command,
54-
Env: opts.Environment,
63+
Env: env,
5564
User: opts.User,
5665
Privileged: opts.Privileged,
5766
Tty: opts.Tty,

0 commit comments

Comments
 (0)