Redis连接ECONNREFUSED 127.0.0.1:6379 [英] Redis connect ECONNREFUSED 127.0.0.1:6379
问题描述
我正在服务器上运行Redis(Redis未在容器中运行),并且我试图连接到具有Node.js应用程序runninng的Container内的Redis。从日志文件中的Dockerfile中使用节点应用程序启动Docker容器时,出现以下错误: Redis与127.0.0.1:6379的连接失败-连接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现在提供了一个名为 host.docker.internal $ c的自定义DNS名称。 $ c>(适用于Windows / Mac版本)(请参见 https ://docs.docker.com/docker-for-windows/networking/#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屋!