Connecting a Dockerized MongoDb instance, behing a reverse Nginx proxy on EC2 - mongodb

I try to connect Robomongo (or any other MongoDb UI) to a mongo instance, which is dockerized and behind an NGinx reverse-proxy (also dockerized, using jwilder/nginx-proxy) on a EC2 Container-Service instance.
err screenshot here
I have an application running using this mongo instance, on the same network, working like a charm ; so we know that mongo is running well.
If I try to access directly the container via a browser and targeting the 443 port, i get the following message :
It looks like you are trying to access MongoDB over HTTP on the native driver port.
I'm using the official mongoDb docker container, which only exposes 27017 ; so my request is redirected from 443 to 27017.
Do you know how can this be achieved ?
Thanks a lot,

Perhaps you need pass the --httpinterface flag to the mongodb container:
docker run --name some-mongo -d mongo --httpinterface
This flag are deprecated since version 3.2: HTTP interface for MongoDB
Check Mongodb Documentation

Related

Cannot access local MongoDB from sam local

I have Windows 10 machine where MongoDB is installed. I can connect it from a command line. I run NodeJS app with sam local. When I use a production environment, the app can access Mongo Atlas cloud instance. But when I switch to a dev environment with localhost MongoDB it fails to connect.
The sam command starts Docker so it is clear why it cannot connect Mongo running on windows localhost. I found relevant question: From inside of a Docker container, how do I connect to the localhost of the machine?. The problem is that I still cannot connect my local MongoDB, even if I try:
"MONGODB_URI": "mongodb://docker.for.win.localhost:27018/bud?retryWrites=true&w=majority"
or
"MONGODB_URI": "mongodb://host.docker.internal:27018/bud?retryWrites=true&w=majority"
Error:
Request failed { MongoNetworkError: failed to connect to server [docker.for.win.localhost:27018] on first connect [MongoNetworkError: connect ECONNREFUSED 192.168.65.2:27018]
Has anybody faced this issue as well and overcome it? Mongo is installed directly to windows, not in Docker.
If MongoDB is installed and running directly from windows, it should be accessible via localhost:27017. Default port for mongod is 27017, as described in mongoDB documentation page.
Try using:
"MONGODB_URI": "mongodb://localhost:27017/bud?retryWrites=true&w=majority"
If you are using NETWORKS_DRIVER other than bridge for your NodeJS docker container, which is set by default. Refer to Docker Network drivers
Other cases:
The default port for mongod is 27018 when running with --shardsvr command-line option or the shardsvr value for the clusterRole setting in a configuration file.
The default port for mongod is 27019 when running with --configsvr command-line option or the configsvr value for the clusterRole setting in a configuration file.
Remember, that localhost (or any name) is just for your convinience. Tcp stack works on ip addresses. If you configure dns service (e.g. via hosts file) to resolve name to 127.0.0.1 for container it doesn't mean your host, but 127.0.0.1 points to the container, always.
You could make mongo service to listen on your main ip and use it for docker app, but you can also leverage hyper-v virtual network cards and setup mongo to listen not only on host's loopback interface, but also on the virtual one and give docker app ip of that interface. It remains on your virtual lan, therefore it's not exposed to public. However, windows firewall might block it, so make sure you set it up as private network (it will be marked as unidentified and by default is public, which usually has stuff blocked).

Connect mongo with meteor in production

I have deployed my meteor application on localhost for demo purpose by following what was mentioned here.
$export MONGO_URL='mongodb://localhost'
$ export PORT=3000
$ export ROOT_URL='http://example.com'
$ node main.js
I have had a bunch of collections in my meteor's mongo instance while development and need to move it to the new db that the deployed version connects to. I've taken a mongo dump of that and I know how to restore it. My question is, how exactly do I connect to the mongo db in order to do this?
I've tried:
mongo localhost
mongo localhost:3000
mongo -U localhost
They don't seem to work.
NOTE -
I do not want to run the mongo in development environment using meteor mongo. I have to deploy this in the client machine.
You can use the Meteor command line tools to attach to your local meteor instance.
meteor mongo
Taken from https://docs.meteor.com/commandline.html#meteormongo
Also, I think your commands didn't work 'cause the meteor mongo instance is hosted on port 3001 instead of 3000. Port 3000 hosts the actual meteor app, 3001 is the mongo instance.
As k.chao.0424 says you can use meteor mongo to connect to the mongo db via terminal or command line if you are using windows. But as i see you used the port 3000 for mongodb. I suggest you a simple way you just run the follwing command to run meteor and mongo db just write on your terminal:-
meteor
or if you are using ubuntu and any permission issues than write:-
sudo meteor
It will automatically run your project on 3000 port and your mongdb in 3001 port as by default after running app you can connect with mongodb via following command:-
meteor mongo
Hope this will help!

connect robomongo to mongoDB docker container

I'm running a NodeJS App with docker-compose. Everything works fine and I can see all my data by connecting to Mongo inside container. But when I connect to RoboMongo I don't see any data.
How can I deal with this problem?
There is another way. You can
SSH with Robomongo into your actual virtual server that hosts your docker applications (SSH tab, check "Use SSH tunnel" and complete the other fields accordingly)
Now ssh into the same machine in your terminal.
docker ps should show you your MongoDB container.
docker inspect <mongo container id> will print out complete information about that container. Look for IPAddress in the end, that will give you the local IP of the container.
In the "Connection" tab in Robomongo use that container IP to connect.
Another sidenote: Make sure that you don't expose your mongodb service ports in any way (neither Dockerfile nor docker-compose.yml), cause that will make your database openly accessible from everywhere. Assuming that you don't have set up a username / password for that service you will be scanned and hacked soon.
The easiest way is to enable forwarding the Mongo Container itself, here's how my docker-compose looks like.
mongo:
image: mongo
restart: always
ports:
- 27017:27017
You should do a Robomongo SSH tunnel connection to MongoDB inside docker container. First of all you should install a ssh server inside your docker container.
https://docs.docker.com/engine/examples/running_ssh_service/
After that you should configure your connection in Robomongo.
Inside "Connection Settings" there are configuration tabs of your Robomongo Connection.
Go to "SSH" Tab and configure your SSH connection to the docker container. After that go to "Connection" Tab and configure your connection to MongoDB as if it was in localhost scope.
I was facing a different problem. I had installed MongoDB locally. So, when the MongoDB on docker was running, it was clashing with the one running on my host. I had installed it using brew.
So, I ran
brew services stop mongodb-community
and then I restarted Robo3t. I saw the databases created in the MongoDB running on the docker.
Voila!
Please note that maybe you won't be able to use ssh because it was just a problem of incompatibility between mongo and robomongo.
'Robomongo v8.5 and lower doesn't support MongoDB 3'. It has nothing to do with docker.
First log in with ssh Login details
ssh -i yourpemfile.pem username#ipaddress
Check running container id for MongoDB
docker ps -a
then check the mongo container id
docker inspect container_id
Then open robo3t
create new connection and add container id
use ssh login details to connect to mongodb
In your docker-compose file, you can expose a port to the host.
For example, the following code will expose port 27017 inside the machine to the port 27018 in the host.
app:
image: node
volumes:
- /app
ports:
- "27018:27017"
Then, if you have docker-machine installed and your machine is default, you can do in a terminal :
docker-machine ip default
It will give you the ip of your host, for example 192.168.2.3. The address of your database (host) will be 192.168.2.3 and the port 27018.
If your docker machine is not virtual and is your OS, the address of your database will be localhost and the port 27018.

How to connect mongodb clients to local Meteor MongoDB

How can I connect Robomongo (or any other mongodb client) to the mongodb instance that is created by my local Meteor application?
Ensure Meteor is running on localhost. Open a terminal window and run meteor command. It will start running on localhost:3000 if you have not changed to port.
While it is running, open a separate terminal window and run meteor mongo command. This will open up a MongoDB shell and tell you what port it is connecting to This is normally 3001 as of version 0.7.1.1 or 3002 if earlier. It will say something like 127.0.0.1:3001/meteor
Go to Robomongo (or your favorite mongodb client software) and create a new connection, making sure to change the connection address to localhost and the given the port number. No need to additionally define /meteor if your client does not insist on a default database.
Also as pointed out in https://stackoverflow.com/a/22023284/1064151 some drivers may need specific line endings, delimeters or other character flow. For example, ObjCMongoDB a C based driver wants the url to be 127.0.0.1:3001/ with that extra / at the end, or it won't work. So make sure you check the documentation for your driver/client.
Easiest way to get the current configuration details is to use the following command
meteor mongo -U
This will give you the connection string
From terminal run following command
meteor mongo -U
That will show you the local host IP address and in which port you application is running. Now run the Robomongo and configure as following two field as you got by running the previous command
Use SSH tunneling by the following command :
ssh -L 3001:localhost:3001 user-name#host
It forwards connections from your local port 3001 to localhost:3001 on your server. Now we can simply connect to our database.
Create a Robomongo connection on your localhost and hit Test (Out of two checks, Authentication may fail) :
I'm using ObjCMongoDB, a C based mongoDB driver. With the new update instead of using the previous 127.0.0.1:3002 to connect to my localhost running meteor's mongodb, I now need to use 127.0.0.1:3001/ with the collection name still being meteor.collection. The important change is the port from :3002 to :3001/. Remember the /, it is critical for the connection.
This worked for me,Before connecting make sure meteor is running.
I am using Robomongo to connect. Create new connection and add
Address as : localhost;
port as: 3001
I'm too using Robomongo and before the latest update V0.7.1,i used port 3002 to connect,as #Serkan Durusoy suggest's for the latest update it is working for 3001 port
#imal365 answer is perfect. Just to add my insight on it:
I realized that the default Meteor Mongo port number is the port number of the application with 1 added to it (as of version 0.7.1.1). In my case, I was running Meteor on port 1337 with the command meteor --port 1337 and my Meteor Mongo port was 1338.

How to identify the port of minimongo running inside meteor?

I am novice in meteor. I was developing an application which leverages the mongo db which comes with the meteor package. The meteor is running under the port 3000, but i want to know under what port the mini mongo runs. I am using a tool MongoVUE to view all the collections that is under mongo running in a port. I was able to view the mongo collections when i run the standalone mongo since i know the port for that but for this mini mongo running under meteor i am not able to know the port. Any help is appreciated.
Mingomongo runs in the browser, it's a client-side Javascript library.. it runs in memory, it doesn't have a port.. it enables you to query data published by the server in your client application, using MongoAPI style syntax..
to get the connection string of the Mongo instance running on the server (say, if you want to connect from a different client, or just see the port number) run
meteor mongo -U
Using ps auxww|grep mongo|grep meteor on my Fedora system I get:
jwulf 20635 0.3 2.6 150800 41336 pts/1 Sl+ 17:07 0:01 /usr/lib/meteor/mongodb/bin/mongod --bind_ip 127.0.0.1 --smallfiles --port 3002 --dbpath /home/jwulf/tools/leaderboard/.meteor/local/db
So it is running on port 3002 on my system. Starting mongo with --port 3002 allows me to connect to the Meteor mongo server and copy data into the database.
You can also connect to the local instance by running meteor mongo in your Meteor app directory.
The database itself is at <app-name>/.meteor/local/db on my Fedora system.
In meteor 0.8.3 it's using port 3001
so I run:
mongo localhost:3001
use use meteor
and I'm good to go...thanks to Sitapati Das for the command above...