我有一个使用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终端中发出以下命令时,我得到的结果是fine
$ 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