diff --git a/libnetwork/drivers/windows/port_mapping.go b/libnetwork/drivers/windows/port_mapping.go index 51791fd111..4ad25c1e79 100644 --- a/libnetwork/drivers/windows/port_mapping.go +++ b/libnetwork/drivers/windows/port_mapping.go @@ -48,6 +48,12 @@ func allocatePort(portMapper *portmapper.PortMapper, bnd *types.PortBinding, con err error ) + // Windows does not support a host ip for port bindings (this is validated in ConvertPortBindings()). + // If the HostIP is nil, force it to be 0.0.0.0 for use as the key in portMapper. + if bnd.HostIP == nil { + bnd.HostIP = net.IPv4zero + } + // Store the container interface address in the operational binding bnd.IP = containerIP diff --git a/libnetwork/drivers/windows/windows.go b/libnetwork/drivers/windows/windows.go index c8ab047592..b8a5f73b96 100644 --- a/libnetwork/drivers/windows/windows.go +++ b/libnetwork/drivers/windows/windows.go @@ -462,7 +462,7 @@ func ConvertPortBindings(portBindings []types.PortBinding) ([]json.RawMessage, e return nil, fmt.Errorf("Windows does not support more than one host port in NAT settings") } - if len(elem.HostIP) != 0 { + if len(elem.HostIP) != 0 && !elem.HostIP.IsUnspecified() { return nil, fmt.Errorf("Windows does not support host IP addresses in NAT settings") }