Docker redis Connection refused 问题排查

问题描述:

用 docker分别运行2个容器,一个spring boot应用,一个是redis

 然后发现Spring boot项目无法访问redis。在本地启动Spring boot项目可以访问Redis,然后打成JAR直接启动也能访问。但是做成容器访问Redis却总是报错。

2022-12-16 06:51:27.191 ERROR 1 --- [nio-8080-exec-2] 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: Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379] with root cause

java.net.ConnectException: Connection refused
 

 springboot配置

 redis的配置

排查问题:

 首先查看Docker网络配置,命令:

docker network ls

查看bridge的网络配置

可以看到2个容器的IP地址分别是172.17.0.3和172.17.0.2

运行tcpdump命令发现只有172.17.0.3的IP

初步怀疑是配置地址IP写的不对,把项目的地址改成docker的地址后问题解决。

 

 这个问题其实虽然不难,但我们可以从中学习docker的网络问题。包括可以用命令分别在两个容器直接PING 

执行ping命令

docker exec -it fdb2b3e99e93(容器ID) /bin/bash

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值