'Springboot connected redis built in docker with wrong address

I built redis cluster with docker.

The address of the host is 10.1.233.23.

here is my steps of creating redis cluster:

docker network create --subnet=172.110.0.0/16 redis-net
docker run -d --name r1 -p 7001:6379 --net=redis-net --ip 172.110.0.2 myredis:1.0
docker run -d --name r2 -p 7002:6379 --net=redis-net --ip 172.110.0.3 myredis:1.0
docker run -d --name r3 -p 7003:6379 --net=redis-net --ip 172.110.0.4 myredis:1.0

Redis cluster works.

Here is the configuration in application.properties:

spring.redis.cluster.nodes=10.1.233.23:7001,10.1.233.23:7002,10.1.233.23:7003

the error log is

[ioEventLoop-4-3] i.l.core.cluster.RedisClusterClient      : connection timed out: /172.110.0.2:6379
[ioEventLoop-4-3] i.l.core.cluster.RedisClusterClient      : connection timed out: /172.110.0.3:6379
[ioEventLoop-4-3] i.l.core.cluster.RedisClusterClient      : connection timed out: /172.110.0.4:6379

I discoveried springboot had tryed to connect redis nodes with the docker ip not 10.1.233.23.

How to solve this problem?

I really appreciate your geneous help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source