Docker container running on Linode server unable to connect to mongo atlas cluster - node.js

I'm trying to connect the node in Docker container which is running on my Linode server. I'm getting the following error.
MongoDB connection error. Please make sure MongoDB is running. MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
If I run the same image in my local system everything works fine. DB connection is successfully establishing.
I added the docker IP address in the atlas cluster as whitelisted.
I added my server IP address in the atlas cluster as whitelisted.
I used the below command to get the Ip of my docker container.
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <containerId>
Even after adding the IP of the container DB connection is throwing the error.
Since I'm new to docker Please let me know if I'm missing any steps in between or doing something wrong.

Related

Depending on HOST NAME value for PostgreSQL database in my .env file I get different result

I have created a PostgreSQL with a web server DOCKER CONTAINER and my app running with an API to manage all the endpoints.
The link of my git repo is: https://github.com/JulioValderrama/store-front-project.git
But I am facing problems with the connections with the Database, as depending on the Postgres HOST name value in my .env file one of the two servers (one local running in PORT 4000 and the web server running in the docker container in PORT 3000) will work or will fail.
I have tried the next:
Local server running in PORT 4000
Docker web server running in PORT 3000
HOST "127.0.0.1"
Going to¨:
http://localhost:3000/
Works fine and get response, now when trying to connect it to any of my database API:
http://localhost:3000/products
I get the error:
"Could not get PRODUCTS. Error: Error: connect ECONNREFUSED 127.0.0.1:5432"
Going to:
http://localhost:4000
Works fine and get response, now when trying to connect it to any of my database API:
http://localhost:4000/products
It works! I get the list of all my products!!
HOST "postgres"
I put "postgres" because I read online that you have to name HOST as the postgres docker image created, which is my case. And it works for the remote server.
Going to:
http://localhost:3000
Works fine and get response, then when trying to connect it to database API:
http://localhost:3000/products
It works!! It gives me the list of my products !!
Going to:
http://localhost:4000
Works fine and get response, then when trying to connect it to database API:
http://localhost:4000/products
It gives me the error:
"Could not get PRODUCTS. Error: Error: getaddrinfo ENOTFOUND postgres"
So it seems like there is an error when trying to connect to the database due to the server or the HOST name, I have no idea....
In docker-compose.yaml you have linked your machine 5432 to containers 5432 port.
If you are using docker container and want to reach postgres, use postgres as POSTGRES_HOST value.
If you are running application outside the docker environment use 0.0.0.0, 127.0.0.1.
Make sure you haven't installed postgres locally
brew uninstall postgres

Docker cannot access mariadb server

I am newbie on docker.
I want to migrate my nodejs app to docker, and existing database already installed on server (172.17.2.1). I set mariadb host 172.17.2.1 on my nodejs config.
After that, I created an images and run with :
docker run -p 3009:3009 -d my-node
actually its already running, but when I tested to open by browser, I got an error that my app cannot connect to 172.17.2.1 (connecting to database).
I try to create bridge IP (172.17.2.135) and make a same subnet, but still got a same error.
My images on docker inside doesn't know 172.17.2.1 on my LAN.
Please help me,
I use windows 10 environment
You have two options to allow your container to reach an external server:
Run your docker container on your host network:
docker run -p 3009:3009 --network host -d my-node
This way your container will be able to reach anything reachable from your machine
create a network bridge: in this case docker will route the traffic from the container to the external server. the bridge IP can't be your docker machine IP as you tried to do.

connect to mongodb production using robomongo client

in my dev enviorment I use mlab as temp db, but now I have production db setup in my ubuntu server. I can run mongo in my terminal after I ssh into my server, now I'm having problem connecting it with my client software which is robomongo. What step I missed out?
In your mongo (mongod) configuration file (default /etc/mongod.conf), you have to set the net.bindIp setting to ::,0.0.0.0 to bind to all IP addresses what can access to db or you can set only your pc ip address (robomongo belong to the pc) and your node server ip (localhost if nodeserver is the same with db server).

Unable to connect to remote mongodb instance from nodejs deployed on Amazon EC2 VM

I am unable to connect to remote mongodb service deployed using Mlabs. I am able to connect to this service from the node server deployed on my local machine but it does not works when I try to deploy it on Amazon EC2 windows instance.
I have opened the following inbound and outbound rules.
enter image description here
enter image description here
I have also opened the firewall rules for that, but still it does not works.
I am trying to connect to it using mongoose in nodejs.
mongoose.connect('mongodb://user:pass#ds031947.mlab.com:31947/db');
As you said its accessible from your local system so most probably you have your bind-ip set to localhost instead of public ip.
open your /etc/mongodb.conf and make sure the bind ip is set to public access not local host.
run on EC2 instance:
netstat -pl
the output must shows
tcp 0 0 0.0.0.0:27017 : LISTEN 2025/mongod
if it shows localhost:27017 you have to change the config file to make it accessible to public.
Hope it will help !

Connecting to remote cassandra database

I am trying to connect to a remote cassandra database using dbeaver.
I installed cassandra over an ubuntu machine from digital ocean, and I am running the dbeaver from my local machine.
When I leave the default /etc/cassandra/cassandra.yaml file, and then run the netstat -ntlp | grep 9420 I find that the connection is on and waiting for connection but once I update both the listen_address and the rpc_address to the public IP address of the remote machine, I found that I am no longer able to connect even locally to the database, using cqlsh cli.
What are the steps I should do to connect to a remote cassandra database, I read a lot of articles, but obviously there is something missing I can't understand

Resources