Docker compose spring boot redis connection issue

試著忘記壹切 提交于 2019-12-12 20:08:08

问题


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.


回答1:


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"


来源:https://stackoverflow.com/questions/51488311/docker-compose-spring-boot-redis-connection-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!