From 10df1f55f15948905554822f7d0c270a7335a87f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 13 Jul 2019 01:53:12 +0200 Subject: [PATCH] daemon: don't listen on the same address multiple times Before this change: dockerd -H unix:///run/docker.sock -H unix:///run/docker.sock -H unix:///run/docker.sock ... INFO[2019-07-13T00:02:36.195090937Z] Daemon has completed initialization INFO[2019-07-13T00:02:36.215940441Z] API listen on /run/docker.sock INFO[2019-07-13T00:02:36.215933172Z] API listen on /run/docker.sock INFO[2019-07-13T00:02:36.215990566Z] API listen on /run/docker.sock After this change: dockerd -H unix:///run/docker.sock -H unix:///run/docker.sock -H unix:///run/docker.sock ... INFO[2019-07-13T00:01:37.533579874Z] Daemon has completed initialization INFO[2019-07-13T00:01:37.567045771Z] API listen on /run/docker.sock Signed-off-by: Sebastiaan van Stijn (cherry picked from commit d470252e8742867797a58933f7b4ba34494af2ed) Signed-off-by: Sebastiaan van Stijn --- cmd/dockerd/daemon.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index 863628b63b..607604392f 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -608,11 +608,17 @@ func newAPIServerConfig(cli *DaemonCli) (*apiserver.Config, error) { func loadListeners(cli *DaemonCli, serverConfig *apiserver.Config) ([]string, error) { var hosts []string + seen := make(map[string]struct{}, len(cli.Config.Hosts)) + for i := 0; i < len(cli.Config.Hosts); i++ { var err error if cli.Config.Hosts[i], err = dopts.ParseHost(cli.Config.TLS, honorXDG, cli.Config.Hosts[i]); err != nil { return nil, errors.Wrapf(err, "error parsing -H %s", cli.Config.Hosts[i]) } + if _, ok := seen[cli.Config.Hosts[i]]; ok { + continue + } + seen[cli.Config.Hosts[i]] = struct{}{} protoAddr := cli.Config.Hosts[i] protoAddrParts := strings.SplitN(protoAddr, "://", 2)