我在本地nodejs应用程序上运行redis(docker镜像)

问题描述 投票:2回答:2

我正在尝试在本地节点js应用程序上使用redis连接,但它抛出一个错误---

events.js:183 throw er; //未处理的'错误'事件^

错误:Redis连接到127.0.0.1:6379失败 - 在TCPConnectWrap.afterConnect连接ECONNREFUSED 127.0.0.1:6379 [as oncomplete](net.js:1191:14)

enter image description here

enter image description here

running none docker image

running docker image

node.js docker redis
2个回答
0
投票

如果我理解正确,您正在Docker容器中运行节点。此节点进程正在尝试访问在localhost上运行的redis实例。

这不起作用,因为容器(节点)有自己的网络堆栈,而127.0.0.1没有指向主机。

在这种情况下,你需要

  1. 在自己的容器中运行redis(并使用例如docker-compose)或
  2. 将redis的节点连接主机从localhost(或127.0.0.1)更改为主机IP地址。请参阅How to get the primary IP address of the local machine on Linux and OS X?以查找IP地址

0
投票

您正在尝试连接到错误的端口。正如docker ps命令所说,redis正在收听的端口是32768。连接到该端口应该可以解决您的问题。

有关自定义端口侦听的更多信息,请参阅the official docker documentation(特别是标志-p)。

© www.soinside.com 2019 - 2024. All rights reserved.