2

I am running a simple rest app with redis running in a docker container/docker-compose. I believe, redis must be accessible to spring boot using http://redis:6379. But, it throws the error:

018-07-22 21:53:33.972 ERROR 1 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool] with root cause

java.net.ConnectException: Connection refused (Connection refused)

My code is here.

nickgryg
  • 25,567
  • 5
  • 77
  • 79
GAK
  • 1,018
  • 1
  • 14
  • 33

1 Answers1

3

Since you are using alias in links, you have to use the hostname identical to the alias to access the container. Therefore you can do one of following,

use http://localhost:6379 instead of http://redis:6379 in your spring boot application

or,

change

links:
 - "redis:localhost"

to

links:
 - "redis"
Dilan Tharaka
  • 517
  • 5
  • 15