【问题标题】:Vue app not able to connect to Docker RedisVue 应用程序无法连接到 Docker Redis
【发布时间】: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


【解决方案1】:

我可以通过以下命令重新创建 redis 映像来打开端口,其中我添加了端口转发部分

 docker run -d --name local-redis -p 6379:6379 -d redis

【讨论】:

    猜你喜欢
    • 2018-07-12
    • 2021-10-23
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 2023-02-10
    • 2015-06-10
    相关资源
    最近更新 更多