Cannot connect Robomongo using MongoDB docker image - mongodb

I am running mongo docker image that I pulled from docker hub mongo image
It works ok but when I start Robomongo I cannot connect to localhost. With following error message:
Cannot connect to the MongoDB at localhost:27017.
Error:
Network is unreachable
I appreciate any help, thanks.
EDIT: I solved the issue by using the following command:
docker run -p 27017:27017 --name mongo_instance_001 -d mongo

Don't forget to map port to host port:
docker run --name some-mongo -p 27017:27017 -d mongo
Then
docker-machine ip
gives me 192.168.99.100
Type in terminal
mongo 192.168.99.100
prints
MongoDB shell version: 3.2.4
connecting to: 192.168.99.100/test
Server has startup warnings:
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten]
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten]
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten]
I also tested with robomongo. I can connect without a problem.

you can find docker-machine ip just typing this command
docker inspect
container id is sha256

Related

SocketException: Address already in use MONGODB

i found this error when trying to run mongodb. I install it via homebrew. Please assist
Agungs-MacBook-Pro:~ agungmahaputra$ mongod
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] MongoDB starting : pid=5189 port=27017 dbpath=/data/db 64-bit host=Agungs-MacBook-Pro.local
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] db version v3.6.0
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] git version: a57d8e71e6998a2d0afde7edc11bd23e5661c915
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] allocator: system
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] modules: none
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] build environment:
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] distarch: x86_64
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] target_arch: x86_64
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] options: {}
2017-12-26T15:31:15.911+0700 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] now exiting
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] shutting down with code:48
Agungs-MacBook-Pro:~ agungmahaputra$
You can kill the previous mongod instance and start the new one.
To kill the previous mongod instance, first search for a list of tasks running on your machine by typing,
sudo lsof -iTCP -sTCP:LISTEN -n -P
Search for mongod COMMAND and its PID and type,
sudo kill <mongo_command_pid>
Now start your mongod instance by typing,
mongod
You can see MongoDB running successfully.
You already have a process running in the port 27017 which is used by mongodb. So either you need to stop the process in that port or try with different port number.
Try mongod --port 27018
You can change the port number of your choice.
EDIT:
You can also just stop all the running instances of mongo server using
sudo killall mongod as mentioned by #Dassi Orleando in the comments.
And run mongod
Summary other(#Tony Roczz, #Balasubramani M) answer to here:
Root Cause
error: Failed to set up listener: SocketException: Address already in use
means:
previously have run mongodb
probably use default port 27017
Solution
(most case) kill and restart mongod
kill mongod
two method:
use killall
killall mongod
kill by PID
find mongod PID
method 1: ps aux | grep mongod
output can see like this: limao 425 ... /usr/local/opt/mongodb-community/bin/mongod --config /usr/local/etc/mongod.conf
method 2: lsof -iTCP -sTCP:LISTEN -n -P
output can see like this: mongod 425 limao .. TCP 127.0.0.1:27017 (LISTEN)
kill by PID: kill -9 425
re-start mongod
most case: mongod
some special case
brew services start mongodb-community
for install community version in Mac by: brew install mongodb-community
(for some people) run with another port
run with another port: mongod --port 27018
only for those want to run multiple mongod server same time
Additional Note
which port the running mongodb is using?
 lsof -iTCP -sTCP:LISTEN -n -P
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 425 limao 10u IPv4 0xab744305e75263cf 0t0 TCP 127.0.0.1:27017 (LISTEN)
can see 27017 is current running mongodb port.
how to check / make sure mongod is running
check mongod status:
ps aux | grep mongod
output can see mongod service
brew services list
if installed by brew and start by brew
if you're using mongodb version 4.*
in default settings, there should be a "db" folder "/data/db" having the necessary permission.
to check it the MongoDB service started
brew services list
if not then run
brew services start mongodb
run mongo instead of mongod
I solved it pasting the command below into the command line in order to close mongo's server.
sudo pkill -f mongod
"sudo" (Super User Do) runs the command admin permissions, so it will ask you for your user password
First, shutdown the running server using:
mongod --shutdown
Then run:
sudo mongod
After running this commands below:
sudo lsof -iTCP -sTCP:LISTEN -n -P
Search for mongod COMMAND and its PID and type,
sudo kill <mongo_command_pid>
And restarting mongod, it still fails with the same error "SocketException: Address already in use MONGODB".
Server was restarted yesterday and then this happened.
Just this single command
sudo pkill -f mongod
Make Sure the error is of the port , if using macos catalina there is a reported issue for ~/data/db which also causes this.
If your mongod process is already down, just remove the .sock file in /tmp:
My mongod is already down, so does not appears in:
lsof -iTCP -sTCP:LISTEN -n -P
The error was:
[root#ol7db19c1 ~]# mongod -f /etc/csrs_2.conf
about to fork child process, waiting until server is ready for connections.
forked process: 6721
ERROR: child process failed, exited with error number 48
To see additional information in this output, start without the "--fork" option.
In the log file (/var/mongodb/db/csrs2.log):
2020-07-05T16:03:59.354-0300 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
So, find for the socket locking:
ls -ltra /tmp|grep .sock
And just remove it (do it with caution in production environment):
rm -f mongodb-26002.sock
G-luck!
This may sound obvious but you should check if mongodb is already running.
So instead of first starting the the DB by running:
sudo mongod
Try directly running:
mongo

Using mongo with docker and nfs storage

I have a glusterfs that works fine when i create a volume on Cent7 using: docker volume create... and providing the type as nfs, here is the full command I use to create the volume:
docker volume create --name sv1_mongovol1 --opt type=nfs --opt device=:/root/gluster/mounts --opt o=addr=172.23.180.79
The above volume works perfectly if I use an "alpine" container or sth similar and mount it, the files i touch/create, get written to remove storage, but when I launch a mongo container, it fails. This is how I am launching:
docker run --privileged --rm -it -p 27017:27017 -v sv1_mongovol1:/data/db --name mongodb mongo
And here is the error log
017-02-26T02:31:00.391+0000 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to lock file: /data/db/mongod.lock No locks available. Is a mongod instance already running?, terminating
2017-02-26T02:31:00.391+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-02-26T02:31:00.391+0000 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-02-26T02:31:00.391+0000 I CONTROL [initandlisten] now exiting
2017-02-26T02:31:00.391+0000 I CONTROL [initandlisten] shutting down with code:100
I posted here also:
https://github.com/docker-library/mongo/issues/30

MongoDB - shutting down with code 48

I am trying to start MongoDB but the terminal returns the following error:
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] MongoDB starting : pid=25184 port=27017 dbpath=/data/db 64-bit host=Janiss-MacBook-Pro.local
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] db version v3.4.1
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] allocator: system
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] modules: none
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] build environment:
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] distarch: x86_64
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] options: {}
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] addr already in use
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] Failed to set up sockets during startup.
2017-02-06T16:26:27.038+0000 E STORAGE [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets
2017-02-06T16:26:27.038+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-02-06T16:26:27.038+0000 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-02-06T16:26:27.039+0000 I CONTROL [initandlisten] now exiting
2017-02-06T16:26:27.039+0000 I CONTROL [initandlisten] shutting down with code:48
I am using Laravel Valet if that matters.
It seems like you have already a process running on the port where you want to start mongodb:
listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] addr already in use
you could try to kill the process that runs on that port with this command:
sudo kill sudo lsof -t -i:27017
or define another port for mongodb if you have another program using that port.
to run mongodb on a port other than its default port (27017) use the --port 27018 argument when starting mongodb from the terminal
If you are using mac then you can simply kill the process running on port 27017 which is mongodb process in most cases.
Simply run the command.
npx kill-port 27017
After that you can run the mongod command as you normally do.
Or if you are using windows follow these steps
Run command line as Admin
netstat -ano | findstr :27017
you will get pid in the end that is the process id to kill
taskkill /PID <typeyourPIDhere> /F
after successful termination of process you can run mongod as you usually do!
Enjoy!
This has worked for me
Initially i was facing various issues, like when i tried to start the server by using:
sudo mongod
then i changed port for mongodb
sudo mongod --port 27018
Now mongod server is running tentatively
sudo mongod
Basically you just need to force quit the mongo, you can do this just by typing
sudo pkill -f mongod
and now you can start the server again with
mongod
For me the kill process did not work. Probably because my mongo instance was running on AWS. So, what I did was log onto a mongo shell. (This was possible as mongo instance is running) And switched to the admin DB thru 'use admin' and did 'db.shutdownServer()'. And that shut down the server cleanly
use admin
db.shutdownServer()
I had the same issue (MongoDB failed to start with exit code 48) after a reboot, as it could not bind to the given IP.
It turned out, that the mongod systemctl unit file was configured to launch the mongod service after the network.target. I changed this to network-online.target and it seems to work.
1.And if the mongod show error (shutting down with code 48) that
means the port is being already use so you can do two things
1.a Either you change the port of mongod by specifying port
number
mongod --dbpath /System/Volumes/Data/data/db (path of db) —port 27018
1.b Or You can kill the process at that port by finding
the process by
sudo lsof -i :27017
and then kill by command
kill -9 <PID>
2.Starting mongo db using brew services run mongodb-community
3.Type mongod or mongod --dbpath /System/Volumes/Data/data/db(path)
How I solved my issue?
I don't know the actual reason for this error and its solution but I deleted mongodb database folders C:\data\db and restarted my PC.
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017.
It means the server 27017 is already in use.
You can try mongod --dbpath /System/Volumes/Data/data/db --port 27018.
Or
You can first stop the mongod by sudo pkill -f mongod.
Then restart the server by mongod --dbpath /System/Volumes/Data/data/db
In some cases we may be unaware of the process id where we have initiated mongodb , and we are not able to track it, as we might have forgot to shut it down in such cases:
step 1: first of all try to know the process id where it is being established, and
to know that, type below code in terminal:
lsof -i | grep 27017
Once you type the above code, you will be able to see process id's using your mongodb server:
enter image description here
As you can see in the above picture, there you can find that "9663" is the process id where your mongodb server is active.
Step 2: Now we need to kill this process, by typing the command:
kill <pid>
In the above code pid stands for process id, as shown in the above image the process id looks similar to that of "9336".
Step 3: Now we have successfully killed the process and then we are good to start
the server of mongodb using the command:
mongod
Now you are good to go!

Difference between "mongo" and "mongod"?

I've installed MongoDB and I've found some unlogical things and I hope someone will answer me:
When I execute "mongo" I get logged into shell
When I execute "mongodb" I get the following errors:
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] MongoDB starting : pid=7221 port=27017 dbpath=/data/db 64-bit host=debian
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] db version v3.2.7
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] git version:
4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] modules: none
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] build environment:
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] distmod: debian71
2016-06-23T22:58:39.303+0000 I CONTROL [initandlisten] distarch: x86_64
2016-06-23T22:58:39.303+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-06-23T22:58:39.303+0000 I CONTROL [initandlisten] options: {}
2016-06-23T22:58:39.325+0000 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2016-06-23T22:58:39.325+0000 E NETWORK [initandlisten] addr already in use
2016-06-23T22:58:39.325+0000 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-06-23T22:58:39.325+0000 I CONTROL [initandlisten] dbexit: rc: 48
What is the difference between two terminal commands: mongo as a first, and mongodb as a second?
MongoDB is great because my project is schema-less but it's always a horrible experience to configure it, create roles, authorization etc.
Thanks.
mongod is the server, to which requests to connect database are passed for example.
In above error, it shows that port address 27017 is in use. It means your mongod is already runnning. You just need to run command 'mongo' to access the Mongodb shell.
There is another possibility that some other process is running on port 27017
netstat -n | grep 27017 to check if process is running and kill -9 $(lsof -ti:27017)'
To use any database service, you have to start the database Server and same is the case with mongodb, the command mongod is used to start the MongoDB Server on your local machine or server.
In your question you have asked for the command mongodb that's not correct you need to run command mongod, 'b' is not the part of this command.
When you run the mongod, it starts your mongodb server on default
port 27017.
Then you open another terminal and use the command mongo to enter
into the mongo shell and perform your database operations.
The difference between the both commands is that mongod starts the
mongodb server and mongo allows you to enter into mongo shell to
perform further database operations.
Also, when you install mongodb, you have an option to install it as a service. Installing mongodb as a service starts the mongodb server in background when you boot your system.

Problems on migrating Parse.com app to AWS EC2 Ubuntu

I have an EC2 machine with Ubuntu installed on it. On the machine, I have installed Node.js, MongoDB, and Github version of Parse Server.
I have created a database called euro. In this database, I've created a user using this code:
> use euro
switched to db euro
> db.createUser(
... {
... user: 'username',
... pwd: 'password',
... roles: [ { role: 'readWrite', db:'euro' } ]
... }
... )
Before migrating the app, I have noticed that in AWS EC2 Instances Managment page, you can see 2 IPs addresses: Public IP and a Private IP, so I used the Public IP.
In the Parse.com settings, I've clicked at the Migrate button, and entered this address:
mongodb://username:password#<ipaddress>:27017/euro
and below the address field, it was written No reachable servers.
What can I do in order to solve it and to migrate the app to my EC2 Instance?
EDIT #1:
I have restarted my AWS server, so my Public IP address has been changed. I've tried to change my connection string to the new IP using this address:
mongodb://username:password#<ipaddress>:27017/euro
But suddenly it shows No reachable servers.
What should I do in order to solve this problem? I want to migrate it as soon as possible.
EDIT #2:
I've checked this command sudo netstat -pan | grep mongod to check on which IP it is listening and I got this output:
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 10945/mongod
tcp 0 0 127.0.0.1:27017 127.0.0.1:45406 ESTABLISHED 10945/mongod
unix 2 [ ACC ] STREAM LISTENING 28614 10945/mongod /tmp/mongodb-2
Is it listening on the Public IP? Private IP? localhost?
I solved it using MongoDB guide and this answer.
The problem was some warnings that I got when I've started the server. Apperently It had prevented Parse.com from connecting to my MongoDB.
$ mongo
MongoDB shell version: 3.0.11
connecting to: test
Server has startup warnings:
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten]
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten]
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten]
>
I wasn't able to solve it because I used this command $ service mongod restart without root permission. I was supposed to use this command $ sudo service mongod restart.