【发布时间】:2021-05-03 00:31:20
【问题描述】:
我有一个 vue 应用程序,它使用 redis 来存储用户会话。但是当我在安装 docker redis 后尝试运行应用程序时,它无法连接到 docker redis。 我正在使用 Windows 10。
启动应用时的错误是
(node:11656) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ERROR Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 22:40:02
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
ERROR Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 22:40:04
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
但是当我在 windows 终端中发出以下命令时,我得到的结果很好
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7883e98ea39a redis "docker-entrypoint.s…" 6 hours ago Up 6 hours 6379/tcp local-redis
为什么应用无法连接到本地 docker redis
我通过这个命令创建了 redis docker 镜像:
docker run --name local-redis -d redis
【问题讨论】:
-
与 vuejs 无关。我觉得你忘记了端口转发(-p 6379:6379)
-
是的,在我添加了端口转发之后它现在正在工作
标签: node.js docker vue.js npm redis