diff --git a/runconfig/config_test.go b/runconfig/config_test.go index 84846e5b1d..784341b08c 100644 --- a/runconfig/config_test.go +++ b/runconfig/config_test.go @@ -247,7 +247,7 @@ func TestMerge(t *testing.T) { volumesUser := make(map[string]struct{}) volumesUser["/test3"] = struct{}{} configUser := &Config{ - Dns: []string{"3.3.3.3"}, + Dns: []string{"2.2.2.2", "3.3.3.3"}, PortSpecs: []string{"3333:2222", "3333:3333"}, Env: []string{"VAR2=3", "VAR3=3"}, Volumes: volumesUser, diff --git a/runconfig/merge.go b/runconfig/merge.go index 34faaf75e7..a154d4caf5 100644 --- a/runconfig/merge.go +++ b/runconfig/merge.go @@ -97,8 +97,15 @@ func Merge(userConf, imageConf *Config) error { if userConf.Dns == nil || len(userConf.Dns) == 0 { userConf.Dns = imageConf.Dns } else { - //duplicates aren't an issue here - userConf.Dns = append(userConf.Dns, imageConf.Dns...) + dnsSet := make(map[string]struct{}, len(userConf.Dns)) + for _, dns := range userConf.Dns { + dnsSet[dns] = struct{}{} + } + for _, dns := range imageConf.Dns { + if _, exists := dnsSet[dns]; !exists { + userConf.Dns = append(userConf.Dns, dns) + } + } } if userConf.DnsSearch == nil || len(userConf.DnsSearch) == 0 { userConf.DnsSearch = imageConf.DnsSearch