Fixes #4714
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
| ... | ... |
@@ -231,7 +231,7 @@ func TestMerge(t *testing.T) {
|
| 231 | 231 |
volumesUser := make(map[string]struct{})
|
| 232 | 232 |
volumesUser["/test3"] = struct{}{}
|
| 233 | 233 |
configUser := &Config{
|
| 234 |
- Dns: []string{"3.3.3.3"},
|
|
| 234 |
+ Dns: []string{"2.2.2.2", "3.3.3.3"},
|
|
| 235 | 235 |
PortSpecs: []string{"3333:2222", "3333:3333"},
|
| 236 | 236 |
Env: []string{"VAR2=3", "VAR3=3"},
|
| 237 | 237 |
Volumes: volumesUser, |
| ... | ... |
@@ -97,8 +97,15 @@ func Merge(userConf, imageConf *Config) error {
|
| 97 | 97 |
if userConf.Dns == nil || len(userConf.Dns) == 0 {
|
| 98 | 98 |
userConf.Dns = imageConf.Dns |
| 99 | 99 |
} else {
|
| 100 |
- //duplicates aren't an issue here |
|
| 101 |
- userConf.Dns = append(userConf.Dns, imageConf.Dns...) |
|
| 100 |
+ dnsSet := make(map[string]struct{}, len(userConf.Dns))
|
|
| 101 |
+ for _, dns := range userConf.Dns {
|
|
| 102 |
+ dnsSet[dns] = struct{}{}
|
|
| 103 |
+ } |
|
| 104 |
+ for _, dns := range imageConf.Dns {
|
|
| 105 |
+ if _, exists := dnsSet[dns]; !exists {
|
|
| 106 |
+ userConf.Dns = append(userConf.Dns, dns) |
|
| 107 |
+ } |
|
| 108 |
+ } |
|
| 102 | 109 |
} |
| 103 | 110 |
if userConf.Entrypoint == nil || len(userConf.Entrypoint) == 0 {
|
| 104 | 111 |
userConf.Entrypoint = imageConf.Entrypoint |