My cassandra docker-compose file:
version: '2'
services:
redis-node-0:
image: docker.io/bitnami/redis-cluster:latest
ports:
- "6370:6379"
environment:
- 'REDIS_PASSWORD=pass'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
redis-node-1:
image: docker.io/bitnami/redis-cluster:latest
ports:
- "6371:6379"
environment:
- 'REDIS_PASSWORD=pass'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
redis-node-2:
image: docker.io/bitnami/redis-cluster:latest
ports:
- "6372:6379"
environment:
- 'REDIS_PASSWORD=pass'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
redis-node-3:
image: docker.io/bitnami/redis-cluster:latest
ports:
- "6373:6379"
environment:
- 'REDIS_PASSWORD=pass'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
redis-node-4:
image: docker.io/bitnami/redis-cluster:latest
ports:
- "6374:6379"
environment:
- 'REDIS_PASSWORD=pass'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
redis-node-5:
image: docker.io/bitnami/redis-cluster:latest
ports:
- "6375:6379"
environment:
- 'REDIS_PASSWORD=pass'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
redis-cluster-init:
image: docker.io/bitnami/redis-cluster:latest
depends_on:
- redis-node-0
- redis-node-1
- redis-node-2
- redis-node-3
- redis-node-4
- redis-node-5
environment:
- 'REDISCLI_AUTH=pass'
- 'REDIS_CLUSTER_REPLICAS=1'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
- 'REDIS_CLUSTER_CREATOR=yes'
I have following java configuration:
String clusterNodes = "localhost:6370,localhost:6371,localhost:6372,localhost:6373,localhost:6374,localhost:6375";
List<RedisNode> redisNodes = Arrays.stream(clusterNodes
.split(","))
.map(s -> {
String[] singleNode = s.split(":");
return new RedisNode(singleNode[0], Integer.parseInt(singleNode[1]));
}).collect(Collectors.toList());
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration();
redisClusterConfiguration.setPassword("pass");
redisClusterConfiguration.setClusterNodes(redisNodes);
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(redisClusterConfiguration);
jedisConnectionFactory.afterPropertiesSet();
beanFactory.registerSingleton("jedisConnectionFactory", jedisConnectionFactory);
When I run the application – I se folowing error:
[java] 23:35:30.094 WARN [main] o.e.jetty.webapp.WebAppContext (WebAppContext.java:554): Failed startup of context o.e.j.w.WebAppContext@441016d6{/,[file:///D:/work/onsolve/mir/acadia/ant-build/****/, jar:file:///***/ant-build
/****/WEB-INF/lib/from-ivy-swagger-ui-3.23.0.jar!/META-INF/resources],UNAVAILABLE} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.mir3.sawtooth.service.redis.RedisConnector#0': Invocation of init method failed
; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Could not get a resource from the pool; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
[java] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:416)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
[java] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
[java] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
[java] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
[java] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
[java] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
[java] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
[java] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
[java] at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401)
[java] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292)
[java] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
[java] at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:890)
[java] at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:558)
[java] at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:853)
[java] at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:370)
[java] at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
[java] at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
[java] at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
[java] at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
[java] at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
[java] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
[java] at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[java] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
[java] at org.eclipse.jetty.server.Server.start(Server.java:419)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
[java] at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[java] at org.eclipse.jetty.server.Server.doStart(Server.java:386)
[java] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[java] at com.mir3.cure.framework.WebAppRunner.startServer(WebAppRunner.java:127)
[java] at com.mir3.acadia.Main.main(Main.java:63)
[java] Caused by: org.springframework.data.redis.RedisConnectionFailureException: Could not get a resource from the pool; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
[java] at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:67)
[java] at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
[java] at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
[java] at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
[java] at org.springframework.data.redis.connection.jedis.JedisClusterConnection.convertJedisAccessException(JedisClusterConnection.java:760)
[java] at org.springframework.data.redis.connection.jedis.JedisClusterStringCommands.convertJedisAccessException(JedisClusterStringCommands.java:556)
[java] at org.springframework.data.redis.connection.jedis.JedisClusterStringCommands.set(JedisClusterStringCommands.java:120)
[java] at org.springframework.data.redis.connection.DefaultedRedisConnection.set(DefaultedRedisConnection.java:274)
[java] at org.springframework.data.redis.connection.DefaultStringRedisConnection.set(DefaultStringRedisConnection.java:946)
[java] at org.springframework.data.redis.core.DefaultValueOperations$3.inRedis(DefaultValueOperations.java:240)
[java] at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:59)
[java] at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
[java] at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
[java] at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
[java] at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:236)
[java] at com.mir3.sawtooth.service.redis.RedisConnector.init(RedisConnector.java:38)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:498)
[java] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
[java] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
[java] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
[java] ... 36 common frames omitted
[java] Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
[java] at redis.clients.util.Pool.getResource(Pool.java:53)
[java] at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
[java] at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:66)
[java] at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:116)
[java] at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
[java] at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
[java] at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
[java] at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
[java] at redis.clients.jedis.JedisClusterCommand.runBinary(JedisClusterCommand.java:60)
[java] at redis.clients.jedis.BinaryJedisCluster.set(BinaryJedisCluster.java:77)
[java] at org.springframework.data.redis.connection.jedis.JedisClusterStringCommands.set(JedisClusterStringCommands.java:118)
[java] ... 52 common frames omitted
[java] Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
[java] at redis.clients.jedis.Connection.connect(Connection.java:207)
[java] at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
[java] at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
[java] at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
[java] at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
[java] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
[java] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
[java] at redis.clients.util.Pool.getResource(Pool.java:49)
[java] ... 62 common frames omitted
[java] Caused by: java.net.SocketTimeoutException: connect timed out
[java] at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
[java] at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
[java] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
[java] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
[java] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
[java] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
[java] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
[java] at java.net.Socket.connect(Socket.java:589)
[java] at redis.clients.jedis.Connection.connect(Connection.java:184)
[java] ... 69 common frames omitted
How to fix it?
P.S.
I use spring-data-redis 2.1.10.Release
UPDATE
based on Andreas response in comment I tried to modify compose file:
version: '2'
services:
redis-node-0:
image: docker.io/bitnami/redis-cluster:6.0-debian-10
volumes:
- redis-cluster_data-0:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=se'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
network_mode: 'host'
redis-node-1:
image: docker.io/bitnami/redis-cluster:6.0-debian-10
volumes:
- redis-cluster_data-1:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=se'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
network_mode: 'host'
redis-node-2:
image: docker.io/bitnami/redis-cluster:6.0-debian-10
volumes:
- redis-cluster_data-2:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=se'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
network_mode: 'host'
redis-node-3:
image: docker.io/bitnami/redis-cluster:6.0-debian-10
volumes:
- redis-cluster_data-3:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=se'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
network_mode: 'host'
redis-node-4:
image: docker.io/bitnami/redis-cluster:6.0-debian-10
volumes:
- redis-cluster_data-4:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=se'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
network_mode: 'host'
redis-node-5:
image: docker.io/bitnami/redis-cluster:6.0-debian-10
volumes:
- redis-cluster_data-5:/bitnami/redis/data
environment:
- 'REDIS_PASSWORD=se'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
network_mode: 'host'
redis-cluster-init:
image: docker.io/bitnami/redis-cluster:6.0-debian-10
depends_on:
- redis-node-0
- redis-node-1
- redis-node-2
- redis-node-3
- redis-node-4
- redis-node-5
environment:
- 'REDISCLI_AUTH=se'
- 'REDIS_CLUSTER_REPLICAS=1'
- 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
- 'REDIS_CLUSTER_CREATOR=yes'
network_mode: 'host'
volumes:
redis-cluster_data-0:
driver: local
redis-cluster_data-1:
driver: local
redis-cluster_data-2:
driver: local
redis-cluster_data-3:
driver: local
redis-cluster_data-4:
driver: local
redis-cluster_data-5:
driver: local
But error still the same
2
Answers
Update:
Since you are running docker on Windows, it’s worth reading this limitation of Windows containers for published ports.
You can try using container’s ip and port. Use below command to get containers ip –
Then verify if you are able to ping your container’s ip or not. If pinging works, you’re good to go.
Original Answer:
Your
docker-compose
worked for me without any problem, did a small change to set the password in your java configuration which otherwise throwsNOAUTH Authentication required
. I have used spring-data-redis-2.3.3 –Below is how my
pom.xml
looks like –Please checkout this GitHub project which has your
docker-compose
and java configuration. Rundocker-compose up --build
and thenmvn spring-boot:run
from the root folder.Note: I have tried this on Ubuntu 18.04.5 LTS
Changing the property spring.redis.ssl from true to false worked fine for me in local Windows OS(Version 10.0.18363 Build 18363).