-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Connecting to Cluster not working with docker ENETUNREACH #2815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I have tried this comment and I can establish a connection. I just added a default
|
so just as an observation, there's a difference between the IP you list in the env and the docker IPs. My guess is you are having the ports from the docker containers be visible on the host (and hence why can connect via localhost via a normal client). However, the cluster itself is setup to resolve via the docker IPs (and hence what they return to the client when it interogates a single node for the cluster setup) and then it fails to connect to 172.30.0.2:6379 as per the error shown. if you try to connect via redis-cli to 172.30.0.2:6379 does it work or does it fail as well? |
if the above is the case - see redis/redis#7460 |
Thank you for taking a look!
From my host: no
Yes docker compose exposes the ports to the host. The internal docker IP range for the bridge net work is 172.30.0.0/16.
If that is the case, feel free to close my issue 👍 |
yea, you have to use the announce ip feature, otherwise redis cluster will enumerate the docker IPs, which is why you get the error. |
I assume you are talking about the missing feature redis/redis#7460? Could you please confirm that the workaround is acceptable? |
ok, you're right, that doesn't help directly. The issue is that its not as much an issue in the client, but an issue in the network setup / redis cluster. I can't figure out a way for redis cluster to distinguish the network it uses for internal communication and the addresses it tells clients to use. Not an expert in that. The easiest solution would be to somehow expose the docker network to be routable from your local machine so that the addresses returned by redis to the client are valid, but it seems the NAT issue above are related. another possible solution would be to use iptables to rewrite all outgoing connection to <docker ip1:port 6370 to 127.0.0.1:6379 for each ip/port in use) https://superuser.com/questions/661772/iptables-redirect-to-localhost |
Any idea why |
Honestly, dont know exactly @leibale any ideas? In glancing at ioredis I see it has a "natMap" mode (unsure what it is, just making guesses here). It's possible the mode is dynamic as well (not just something a user has to setup), i.e. when it connects to 127.0.0.1:6379 it learns that said host is really 172.30.0.2:6379 and hence then is able to map that so it always then connects to 127.0.0.1:6379 for that. It's a cute fix (and perhaps even more than cute, somewhat smart). But it will fail if their is any changes in the cluster (i.e. at runtime new replicas are added, that weren't known originally). but this is just a guess on my part. |
Hey! Could we please reopen this ticket? This is not resolved. The workaround only works to connect to the cluster, but I quickly experienced problems when operating on the docker cluster: e.g.
Increasing the Connecting to a remote Azure Redis cluster resolves the problem. Not related to my code. |
this isn't a bug in node-redis, it could be a feature to add, but its not a bug. The issue is that redis-cluster isn't designed to operate behind a NAT. io-redis seems to have some support for mapping "cluster IP/ports" to a different ip/port. i.e. the azure redis cluster returns to the client the proper ip/ports to connect to. |
Can we please reopen the ticket as a feature request? |
@sjpotter @kirrg001 you can use https://github.com/redis/node-redis/blob/master/docs/clustering.md#node-address-map to map the addresses |
ah great, didn't know about that feature. |
I'll try it asap. Thank you! |
Description
Hi!
My docker setup works great with
ioredis
, but not withnode-redis
.(I can successfully connect to each single node with
createClient
, butcreateCluster
does not work.)Node.js Version
20.13
Redis Server Version
docker.io/bitnami/redis-cluster:7.2
Node Redis Version
4.7.0
Platform
macOS
Logs
The text was updated successfully, but these errors were encountered: