Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2203

How to connect to docker redis cluster from local host

$
0
0

I created redis docker cluster using the script:

Cluster_creation.sh

#------------ bootstrap the cluster nodes --------------------start_cmd='redis-server --port 6379 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes'redis_image='redis:5.0-rc'network_name='docker-it-network'docker network create $network_nameecho $network_name " created"#---------- create the cluster ------------------------for port in `seq 6379 6384`; do \ docker run -d --name "redis-"$port -p $port:6379 --net $network_name $redis_image $start_cmd; echo "created redis cluster node redis-"$portdonecluster_hosts=''for port in `seq 6379 6384`; do \ hostip=`docker inspect -f '{{(index .NetworkSettings.Networks "docker-it-network").IPAddress}}'"redis-"$port`; echo "IP for cluster node redis-"$port "is" $hostip cluster_hosts="$cluster_hosts$hostip:6379 ";doneecho "cluster hosts "$cluster_hostsecho "creating cluster...."echo 'yes' | docker run -i --rm --net $network_name $redis_image redis-cli --cluster create $cluster_hosts --cluster-replicas 1;

this script created the cluster and all the nodes are connected.

enter image description here

However i am not able to connect to this redis cluster through my spring boot application.I tried using localhost:6379 , 127.0.0.1:6379, host.docker.internal:6379 but none of this worked.

How do I expose the redis cluster docker container to be consumed by the application in local?

Note: application isn't running in docker. If application is running in docker, I can access redis with redis endpoint as redis-6379:6379. However can't access directly from the local host machine using localhost:6379

ERROR:

gframework.data.redis.TooManyClusterRedirectionsException: No more cluster attempts left.; nested exception is redis.clients.jedis.exceptions.JedisClusterMaxAttemptsException: No more cluster attempts left.

docker inspect docker-it-network:

{"Name": "docker-it-network","Id": "46fc0aacb845bb6fddf36ba85f57f346414594730299cc28ff85a70e3bff1227","Created": "2021-08-06T14:37:59.189023848Z","Scope": "local","Driver": "bridge","EnableIPv6": false,"IPAM": {"Driver": "default","Options": {},"Config": [                {"Subnet": "172.18.0.0/16","Gateway": "172.18.0.1"                }            ]        },"Internal": false,"Attachable": false,"Ingress": false,"ConfigFrom": {"Network": ""        },"ConfigOnly": false,"Containers": {"1105aea5de2ccaa4bdbd01b849c7ff0447299f407112e586ec3943596d2df2ef": {"Name": "redis-6382","EndpointID": "a3f81288c528d37033ec3f091d00a879022558e58614fe9e73626dcaa136d68e","MacAddress": "02:42:ac:12:00:05","IPv4Address": "172.18.0.5/16","IPv6Address": ""            },"233e19cbad6658a65593fcfc8d50688b9b88e7edc1d5f0b8d959ba640c9a3e74": {"Name": "redis-6383","EndpointID": "e0703f96fd6efaef6a7ebf1af6e22151ae85418f62a501fb042ed58d5a364250","MacAddress": "02:42:ac:12:00:06","IPv4Address": "172.18.0.6/16","IPv6Address": ""            },"3372eaf8ceb5b8024202f5bf0421b5ccc697ca6ccbcded5238b1ac05ef1d81bb": {"Name": "redis-6381","EndpointID": "34e11bb16cd3c41aed6d75b35443d043ab7fedd5719b63c3be1d311fb6bfc9d0","MacAddress": "02:42:ac:12:00:04","IPv4Address": "172.18.0.4/16","IPv6Address": ""            },"45c0ac3378e4c85dfe766e030779c94c39028253744c734ba483154a0fe0d722": {"Name": "redis-6384","EndpointID": "10e43a763b66727ce4f4fc4a90a6a057768772d2c97596454bf2ec4134cc18f7","MacAddress": "02:42:ac:12:00:07","IPv4Address": "172.18.0.7/16","IPv6Address": ""            },"8e757a3c2dbb95f9b330fa7ea0bad6c0cf4485fbeeaae92be2e596bccc02b309": {"Name": "redis-6379","EndpointID": "a4a236ca36f4704667c4634564c7b42e5b8d8c308e381efadb408fe11dfb221c","MacAddress": "02:42:ac:12:00:02","IPv4Address": "172.18.0.2/16","IPv6Address": ""            },"fdeace5cff0a5d8ccb5875863f97033426ce97e07224b5ec24b918a017b1701e": {"Name": "redis-6380","EndpointID": "87c837fdcca1f2c8f7c23f369f61b2aa17014a63d21c10823563a6874526d76d","MacAddress": "02:42:ac:12:00:03","IPv4Address": "172.18.0.3/16","IPv6Address": ""            }        },"Options": {},"Labels": {}    }]

Viewing all articles
Browse latest Browse all 2203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>