Im trying to run a spring boot application with redis locally using docker. The app cannot seems to connect with the redis container.
My Dockerfile
FROM java:8
VOLUME /tmp
ADD target/test-*.jar test.jar
RUN bash -c 'touch /test.jar'
EXPOSE 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/test.jar"]
docker-compose.yml
version: '2'
services:
app:
build: .
ports:
- "8080:8080"
links:
- "db:redis"
db:
image: "redis:alpine"
hostname: redis
ports:
- "6379:6379"
application properties
spring.redis.host=redis
When the application try to connect to the database it throws
Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool] with root cause
app_1 |
app_1 | java.net.ConnectException: Connection refused (Connection refused)
Code that i use to connect to db
@Bean
JedisConnectionFactory jedisConnectionFactory() {
return new JedisConnectionFactory();
}
@Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory());
return template;
}
any help would be really appreciated. Thanks