From 48cb2f03177732823b4091fd3ddd44b2bef2c58e Mon Sep 17 00:00:00 2001 From: LK4D4 Date: Wed, 19 Mar 2014 21:01:20 +0400 Subject: [PATCH] Remove duplication of Dns in config merging. Fixes #4714 Docker-DCO-1.1-Signed-off-by: Alexandr Morozov (github: LK4D4) --- runconfig/config_test.go | 2 +- runconfig/merge.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/runconfig/config_test.go b/runconfig/config_test.go index 46e4691b93..8bbad9effa 100644 --- a/runconfig/config_test.go +++ b/runconfig/config_test.go @@ -231,7 +231,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 3b91aa2af0..79e3951271 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.Entrypoint == nil || len(userConf.Entrypoint) == 0 { userConf.Entrypoint = imageConf.Entrypoint