错误:REDIS连接到127.0.0.1:6379失败 - 连接Econnrefuse 127.0.0.1:6379
正在尝试通过我的docker image(Mac OS X环境)之间的Nodejs Docker
的
FROM node:4.7.0-slim
EXPOSE 8100
COPY . /nodeExpressDB
CMD ["node", "nodeExpressDB/bin/www"]
之间
FROM ubuntu:14.04.3
EXPOSE 6379
RUN apt-get update && apt-get install -y redis-server
我
var redis = require('redis');
var client = redis.createClient();
映像
docker build -t redis-docker .
docker build -t node-docker .
通信:
docker run -p 6379:6379 redis-docker
docker run -p 8100:8100 node-docker
错误:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1078:14)
我应该在订单中做什么才能连接到Node-Docker的Redis?
I'm trying to allow communication between my nodeJs docker image with my redis docker image (Mac OS X environment):
nodeJs Dockerfile:
FROM node:4.7.0-slim
EXPOSE 8100
COPY . /nodeExpressDB
CMD ["node", "nodeExpressDB/bin/www"]
redis Dockerfile:
FROM ubuntu:14.04.3
EXPOSE 6379
RUN apt-get update && apt-get install -y redis-server
nodeJs code which is trying to connect to redis is:
var redis = require('redis');
var client = redis.createClient();
docker build steps:
docker build -t redis-docker .
docker build -t node-docker .
docker run images steps flow:
docker run -p 6379:6379 redis-docker
docker run -p 8100:8100 node-docker
ERROR:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1078:14)
What should I do inorder to connect to Redis from node-docker?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
它应该很好。这是下载链接:
github -redis download download package
我希望它可以正常工作。
It should work just fine. Here's the download link:
Github - Redis Download Packages
I hope it works.
REDIS在一个单独的容器中运行,该容器具有单独的虚拟以太网适配器和IP地址到您的节点应用程序正在运行的容器中。 /links“ rel =“ noreferrer”>链接两个容器或创建用户定义的网络为他们
指定主机
redis
在节点中连接时,Redis客户端尝试连接到redis> redis
容器而不是容器 值localhost
docker compose 默认 容器设置。Redis runs in a seperate container which has seperate virtual ethernet adapter and IP address to the container your node application is running in. You need to link the two containers or create a user defined network for them
Then specify the host
redis
when connecting in node so the redis client attempts to connect to theredis
container rather than the default oflocalhost
Docker Compose can help with the definition of multi container setups.
解决方案
然后用=&gt重建Ur Docker; docker-compoped-build
Solution
Then rebuild ur docker with => docker-compose up --build
在节点中连接时,在函数参数中使用
redis-docker
您传递了服务器IP。When connecting in node, use
redis-docker
in the function argument you pass the server IP.如果已安装了redis,则运行命令
sudo apt-get install install redis-server
,您将运行您的站点。
if redis installed then run command
sudo apt-get install redis-server
Then you will get your site running.
如果您可以创建一个新的Redis Docker实例,请尝试映射容器端口以进行主机:
现在,您可以启动容器并与主机127.0.0.1连接
If you can create a new redis docker instance, try mapping the container port to host:
Now, you can start the container and connect with host 127.0.0.1
您还可以更改 /etc /hosts文件以更新Redis容器的DockErip。
通过使用Docker Inspect查找Docker IP
You can also change your /etc/hosts file to update the dockerip of the redis container.
Find the docker ip by using docker inspect