From 04c383345002ac4ad55cbf417c59b681bdc11728 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 18 May 2021 12:28:29 +0200 Subject: [PATCH] define exec env by merging service env with command line --env Signed-off-by: Nicolas De Loof --- local/compose/exec.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/local/compose/exec.go b/local/compose/exec.go index 57996e106..068b5b3c6 100644 --- a/local/compose/exec.go +++ b/local/compose/exec.go @@ -49,9 +49,18 @@ func (s *composeService) Exec(ctx context.Context, project *types.Project, opts } container := containers[0] + var env []string + projectEnv := types.NewMappingWithEquals(opts.Environment).Resolve(func(s string) (string, bool) { + v, ok := project.Environment[s] + return v, ok + }) + for k, v := range service.Environment.OverrideBy(projectEnv) { + env = append(env, fmt.Sprintf("%s=%s", k, *v)) + } + exec, err := s.apiClient.ContainerExecCreate(ctx, container.ID, apitypes.ExecConfig{ Cmd: opts.Command, - Env: opts.Environment, + Env: env, User: opts.User, Privileged: opts.Privileged, Tty: opts.Tty,