define exec env by merging service env with command line --env

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-05-18 12:28:29 +02:00
parent dbd936b704
commit 04c3833450
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
1 changed files with 10 additions and 1 deletions

View File

@ -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,