I am running redis in docker containers and I am using redis sentinel mode. I have setup the following configuration -
3 redis sentinels nodes
1 redis master node
2 redis slave nodes
I am running all these in my local machine. So in total 6 docker containers running through docker-compose
in bridge networking mode.
All conatiners has port mappings to outside.
All containers can access each other as they are in the same bridge docker network created during running of docker-compose up
.
I have created a Java client using Redisson library to access redis. Configured the client to use redis-sentinel mode as follows -
Config config = new Config();
config.useSentinelServers()
.setMasterName("redis-master")
.addSentinelAddress("redis://127.0.0.1:26379")
.addSentinelAddress("redis://127.0.0.1:26380")
.addSentinelAddress("redis://127.0.0.1:26381")
RedissonClient client = Redisson.create(config);
This is where I am facing the issue. Whenever I try to run some commands on redis through this client, the request goes through sentinel nodes which gives me current redis master node address. But my java client cannot communicate to redis master directly as the ip returned by sentinel node is the internel docker network ip for master node which is not accessible outside docker network and it fails with similar exception as below -
Exception in thread "main" org.redisson.client.RedisConnectionException: Unable to connect to Redis server: 172.21.0.2/172.21.0.2:6379
at org.redisson.connection.pool.ConnectionPool$2$1.operationComplete(ConnectionPool.java:161)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
How to fix this issue? Do I need to run it in some different network mode? or some way to translate this internal docker ip to the actual ip of machine running docker conatiners?