node.js - Vue 应用程序无法连接到 Docker Redis
问题描述
我有一个使用 redis 存储用户会话的 vue 应用程序。但是当我在安装 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
解决方案
我可以通过以下命令重新创建redis映像来打开端口,其中我添加了端口转发部分
docker run -d --name local-redis -p 6379:6379 -d redis
推荐阅读
- node.js - 使用 MongoDB 的 NodeJS 嵌套组聚合
- qt - 在 QML 中使用 Brython
- python - 循环输入直到满足参数或用户输入
- c# - Json.NET TypeNameHandling 和 TypeNameAssemblyFormatHandling
- java - 创建包含收件人、主题、正文和附件的电子邮件
- c# - Unity 中的 C#:在不阻塞主线程的情况下调用 Promise 风格的异步方法
- ubuntu - Anki 上的 LATEX 无法正常显示;Ubuntu 18.10
- c# - 如果 2 个图像匹配,如何使 2 个图片框不可见
- java - 根据条件在jsp forloop中隐藏div标签
- c# - 多级属性的 nameof() 运算符