I am running a redis(docker image) on local nodejs application [duplicate] - node.js

This question already has answers here:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
(7 answers)
Closed 1 year ago.
i'm trying to use redis connection on local node js application but it throwing an error ---
events.js:183
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)

If I understand correctly, you are running node inside a Docker container. This node process is trying to reach redis instance running at localhost.
This does not work, because container (node) has its own network stack, and 127.0.0.1 does not point to the host.
In this case you'd need to either
Run redis in its own container (and use e.g. docker-compose) OR
Change the Node connection host for redis from localhost (or 127.0.0.1) to your host IP address. See How to get the primary IP address of the local machine on Linux and OS X? for finding IP address

You are trying to connect to the wrong port. As the docker ps command says, the port where redis is listening is 32768. Connecting to that port should solve your issue.
See the official docker documentation (in particular the flag -p) for more information about customizing port listening.

You can also resolve this error by redoing your Docker container, just add the "-p 6379: 6379" flag. Example (Redis with persistent date):
docker run --name some-redis -p 6379:6379 -d redis redis-server
--appendonly yes

Related

How to install MongoDB Enterprise 4.4 on remote redhat server?

I followed the instructions listed here, https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-red-hat/, and tried to install on a remote server from my local machine. I ssh from my local machine into the server and performed the steps for installation.
I'm not sure if there are additional steps that need to be completed or whether you have to set Directory Paths that are not the default ones since you are using a server instead of local machine. My current error is when I run mongo from my terminal and I get this error
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
[h699972#csc2cxp00020938 ~]$ mongo --host
sudo vim /etc/mongod.conf and setting bindIp: 0.0.0.0 did not work. Any help would be appreciated.

I can't connect to mongo db in ubuntu

MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-10-01T17:38:22.425+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-10-01T17:38:22.426+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I get an error when I try to run mongo on the terminal.
I tried to reinstall and removed lock file and restarted it, but It still doesn't work. I am using AWS, is it some problem about inbound, outbound of network setting in AWS, Or any other problem?
Like the comments above, if you are trying to connect to a mongodb instance on the same host, using 127.0.0.1 it is a mongodb configuration problem, so, that is not possible to be any AWS Security Rules.
So, considering it is a mongodb problem, first try to repair it inside the host with:
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
sudo service mongodb restart
sudo service mongod status
Refer: https://stackoverflow.com/a/29083477/8407784
After resolved the mongodb config problem, you need to test your connection from another host, setting /etc/mongod.conf - bind_ip = 0.0.0.0 (that means all interfaces), only for testing
Then you need to set your AWS Security Rules on the host instance allowing the external instance to access it on port 27017.

mongodb connect fail in osx

I'm newer to mongode, I use shell to start mongodb service but failed and get following error. What should I do?
mongod log
enter image description here
mongo log
MongoDB shell version v3.4.4
connecting to: mongodb://127.0.0.1:27017
2017-05-07T07:59:40.141+1000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-05-07T07:59:40.142+1000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6
exception: connect failed
Try this. Open terminal, and at the prompt type:
sudo chown -R `id -un` /data/db
Exactly as written. This will give you write access to the /data/db directory which is what Mongo is complaining about. It should prompt you for your password. Once it does enter it and hit enter. After that, kill mongod, if running, and restart.
Make sure the MongoDB server (mongod) is listening on the right interface.
Listening on 127.0.0.1 (loopback interface) will only work locally. If you want to handle remote requests you will have to listen on a network interface that can be accessed remotely. Listening on 0.0.0.0 will listen on all network interfaces.
Step 1: Please check whether you have C:\data\db. If you dont have it create it manually.
Step 2: in command line go to directory of mongodb such as c:\Program files\Mongodb\server\3.4\bin and type *mongod
Step 3: type Mongo
Hopefully its gonna work out for you.

I can't connect to cassandra from nodejs app in docker container

I have a nodejs app inside a docker container (node:7.8.0) using 'bridge' network. I use the cassandra driver to connect with a cassandra server, but it raises timeout exception when initialize the connection:
Error: The host 172.16.210.101:9042 did not reply before timeout 12000 ms
at OperationTimedOutError.DriverError (node_modules/cassandra-driver /lib/errors.js:14:19)
at new OperationTimedOutError (node_modules/cassandra-driver/lib/errors.js:104:33)
at Connection.onTimeout (node_modules/cassandra-driver/lib/connection.js:645:20)
at Timeout._onTimeout (node_modules/cassandra-driver/lib/connection.js:620:10)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
From inside the container, I can ping the cassandra server and do a telnet connection.
Using 'host' network works, and executing the app in a "standard" environment too.
Any help is appreciate.
Ok, I found the solution.
The MTU of my host machine is 1450, and docker0 uses by default 1500. It produces an error.
So, I change the MTU for docker and it works.
I use a debian host and I followed next steps:
Copy the service file:
cp /lib/systemd/system/docker.service /etc/systemd/system/docker.service
Then, edit the "ExecStart" line like this:
ExecStart=/usr/bin/dockerd -H fd:// --mtu=1400
Finally, restart docker:
sudo systemctl daemon-reload
sudo systemctl restart docker
Source:
https://rahulait.wordpress.com/2016/02/28/modifying-default-mtu-for-docker-containers/

How to connect to redis which is running on EC2, from node.js application running on local system using Express.js?

I am writing an Node.js application on Express.js. I have a Redis server installed on an EC2 instance running on UBUNTU Server 16.04. I have installed npm modules for Redis.I have mentioned the port and the host like this:-
var redis = require('redis');
var client = redis.createClient(6379,"127.0.0.1");
When I try connecting to EC2 instance of Redis, I get an error like this:-
events.js:141
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1061:14)
How do I connect to redis which is running on ec2?
from the error message, it seems like redis isn't actually running on your host. i would check that redis is indeed running like this:
ps auxwg | grep redis
and check for a running redis process. another, simpler way would be to use the 'telnet' command to attempt to connect your local redis instance like:
wintermute:~ 07:52:58 melgart$ telnet 127.0.0.1 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
in my case, redis is up and running so i get the 'connected' response. HTH

Resources