Redis 连接 ECONNREFUSED 127.0.0.1:6379 [英] Redis connect ECONNREFUSED 127.0.0.1:6379

查看:158
本文介绍了Redis 连接 ECONNREFUSED 127.0.0.1:6379的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的服务器上运行 redis(Redis 没有在容器中运行),我试图连接到我的容器内的 redis,该容器有一个 Node.js 应用程序正在运行.使用日志中的 Dockerfile 中的节点应用程序启动 Docker 容器时,出现以下错误:Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379

Im running redis on my server (Redis is not running in a container) and I am trying to connect to redis inside of my Container which has a Node.js app runninng. When starting the Docker Container with the node app from my Dockerfile in the logs there is the following error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379

推荐答案

Docker 现在为 Windows/Mac 版本提供名为 host.docker.internal 的自定义 DNS 名称(请参阅 https://docs.docker.com/docker-for-windows/网络/#use-cases-and-workarounds) 解析为主机的内部 IP 地址.

Docker now provides a custom DNS-name called host.docker.internal for Windows/Mac versions (see https://docs.docker.com/docker-for-windows/networking/#use-cases-and-workarounds) which resolves to the internal IP address of the host.

因此,不要在连接字符串中使用 localhost:6379/127.0.0.1:6379,而是将其更改为 host.docker.internal:6379代码>.

So instead of using localhost:6379/127.0.0.1:6379 in your connection string, change it to host.docker.internal:6379.

注意:对于 Linux,有一个解决方法 ->见 https://stackoverflow.com/a/61424570/3761628

Note: for Linux there's a workaround -> see https://stackoverflow.com/a/61424570/3761628

这篇关于Redis 连接 ECONNREFUSED 127.0.0.1:6379的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆