Skip to content

Commit 59db010

Browse files
committed
Better error messages when IP address autodetection fails
This fix tries to improve error messages when IP address autodetection fails, as is specified in 25141. Previously, error messages only indicate that multiple IPs exist when autodetection fails. In this fix, if one interface consists of multiple addresses or multiple interfaces consist of addresses, the error messages output the address names and interface names so that end user could take notice. This fix is verified manually. When multiple addresses exist on multiple interfaces: ``` $ sudo docker swarm init Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (192.168.186.128 on ens33 and 192.168.100.199 on eth10) - specify one with --advertise-addr ``` When multiple addresses exist on single interface: ``` $ sudo docker swarm init Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on interface ens33 (192.168.186.128 and 192.168.55.199) - specify one with --advertise-addr ``` This fix fixes 25141. Signed-off-by: Yong Tang <[email protected]>
1 parent b38c25a commit 59db010

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

daemon/cluster/listen_addr.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
var (
1010
errNoSuchInterface = errors.New("no such interface")
11-
errMultipleIPs = errors.New("could not choose an IP address to advertise since this system has multiple addresses")
1211
errNoIP = errors.New("could not find the system's IP address")
1312
errMustSpecifyListenAddr = errors.New("must specify a listening address because the address to advertise is not recognized as a system address")
1413
errBadListenAddr = errors.New("listen address must be an IP address or network interface (with optional port number)")
@@ -159,6 +158,7 @@ func (c *Cluster) resolveSystemAddr() (net.IP, error) {
159158
}
160159

161160
var systemAddr net.IP
161+
var systemInterface net.Interface
162162

163163
// List Docker-managed subnets
164164
v4Subnets := c.config.NetworkSubnetsProvider.V4Subnets()
@@ -197,7 +197,7 @@ ifaceLoop:
197197
}
198198

199199
if interfaceAddr4 != nil {
200-
return nil, errMultipleIPs
200+
return nil, fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on interface %s (%s and %s)", intf.Name, interfaceAddr4, ipAddr.IP)
201201
}
202202

203203
interfaceAddr4 = ipAddr.IP
@@ -212,7 +212,7 @@ ifaceLoop:
212212
}
213213

214214
if interfaceAddr6 != nil {
215-
return nil, errMultipleIPs
215+
return nil, fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on interface %s (%s and %s)", intf.Name, interfaceAddr6, ipAddr.IP)
216216
}
217217

218218
interfaceAddr6 = ipAddr.IP
@@ -223,14 +223,16 @@ ifaceLoop:
223223
// and exactly one IPv6 address, favor IPv4 over IPv6.
224224
if interfaceAddr4 != nil {
225225
if systemAddr != nil {
226-
return nil, errMultipleIPs
226+
return nil, fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on different interfaces (%s on %s and %s on %s)", systemAddr, systemInterface.Name, interfaceAddr4, intf.Name)
227227
}
228228
systemAddr = interfaceAddr4
229+
systemInterface = intf
229230
} else if interfaceAddr6 != nil {
230231
if systemAddr != nil {
231-
return nil, errMultipleIPs
232+
return nil, fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on different interfaces (%s on %s and %s on %s)", systemAddr, systemInterface.Name, interfaceAddr6, intf.Name)
232233
}
233234
systemAddr = interfaceAddr6
235+
systemInterface = intf
234236
}
235237
}
236238

0 commit comments

Comments
 (0)