diff --git a/command/service/update.go b/command/service/update.go index afa0f807e9..1933ff38eb 100644 --- a/command/service/update.go +++ b/command/service/update.go @@ -524,20 +524,21 @@ func updateLabels(flags *pflag.FlagSet, field *map[string]string) { } func updateEnvironment(flags *pflag.FlagSet, field *[]string) { - envSet := map[string]string{} - for _, v := range *field { - envSet[envKey(v)] = v - } if flags.Changed(flagEnvAdd) { + envSet := map[string]string{} + for _, v := range *field { + envSet[envKey(v)] = v + } + value := flags.Lookup(flagEnvAdd).Value.(*opts.ListOpts) for _, v := range value.GetAll() { envSet[envKey(v)] = v } - } - *field = []string{} - for _, v := range envSet { - *field = append(*field, v) + *field = []string{} + for _, v := range envSet { + *field = append(*field, v) + } } toRemove := buildToRemoveSet(flags, flagEnvRemove)