Custom MongoDb docker image - mongodb

I've created this Dockerfile in order to create an image:
FROM mongo:2.6
MAINTAINER Living Digital Way
COPY ./init.ms .
RUN mongo < ./init.ms
init.ms is like:
use fdb;
db.col.insert({"name": "name1"...});
...
As you can see I'm trying to add some data to my mongo instance.
When I'm building this image I get this message from Docker:
Step 4 : RUN mongo < ./init.ms
04:34:47
04:34:47 ---> Running in 96dd54d94bc6
04:34:47
04:34:47 MongoDB shell version: 2.6.12
04:34:47
04:34:47 connecting to: test
04:34:47
04:34:47 2016-09-07T08:34:47.482+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
04:34:47
04:34:47 2016-09-07T08:34:47.483+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
04:34:47
04:34:47 [91mexception: connect failed
04:34:47 [0m
04:34:47 ERROR: Build step failed with exception
Any ideas?

You should start mongod at first.
FROM mongo:2.6
MAINTAINER Living Digital Way
COPY ./init.ms .
# assume you are in mongo bin directory
RUN mongod -f you-config-path/mongo.conf
RUN mongo < ./init.ms

Related

Connection error while installing mongodb on Fedora 28

I have been trying to install Mongodb but it keeps failing midway. When the download is complete, installation fails with a connection error:
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-08-17T12:26:33.340+0200 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-08-17T12:26:33.340+0200 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
What I've tried:
1. Changing the port:
mongo --port 4332
but it doesn't connect still:
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:4332/
2018-08-17T12:32:55.743+0200 W NETWORK [thread1] Failed to connect to 127.0.0.1:4332, in(checking socket for error after poll), reason: Connection refused
2018-08-17T12:32:55.743+0200 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:4332, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
Reinstalling the DB shows up as complete but I still can't start it. Check out the screenshot
Checking for any config files in /etc/mongo* or /var/lib/: there is none.
Note: There's no mongod service available too.
the installation seem to have worked, but the mongod was not started.
MongoDB need two element :
the "mongo" shell utility, who is used to connect to the database direcly
the "mongod" service, who is the true database programs.
to start the mongod, simply use a cmd and use the "mongod" command. this command may fail if :
the port is already used (default is 27017)
the dbpath directory was not created (default is /data/db)
Fedora repository do not install both at the same time.
the shell is in the repository under the "mongodb" name
the server is under the name "mongodb-server"
so to install both, you need to do
dnf install mongodb mongodb-server
and you can then start the mongod service with
sudo service mongod start
more information

Getting error with mongo commend after install mongodb version 3.6.3

I have facing issues while running mongo commend after successful installation of mongoDB version 3.6.3.
I have run mongo commend and got the following error
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-03-14T18:57:02.928+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-03-14T18:57:02.929+0530 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
Run into the same problem, my error was that I was this command:
sudo mongo service mongod start
Instead of this:
sudo service mongod start
Make sure you run the second one, hopefully that is your error source as well.

How to connect to MongoDB

I am conecting mongo db everyday ,it worked fine but today it troubled me with the below error,can anyone help me please.
MongoDB shell version: 2.6.10
connecting to: test
2017-01-10T14:26:13.073+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-01-10T14:26:13.074+0530 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
Run the following command
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart

Install Mongo 3.2.9 on Ubuntu 15.10

i installed mongodb in ubuntu usinfg the following links
https://askubuntu.com/questions/724749/install-mongo-3-2-on-ubuntu-15-10
root#karthickeyan:/home/karthickeyan# mongo
MongoDB shell version: 3.2.9
connecting to: test
2016-08-20T01:17:08.198+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-08-20T01:17:08.198+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
Create the file /lib/systemd/system/mongod.service with the following content:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf
[Install]
WantedBy=multi-user.target
Start the service:
sudo service mongodb start
Then run the command:
mongo
You will then access the server. Hope it works for you. :)

fail to start mongodb-linux-2.4.1 on Ubuntu 12.04

I have downloaded the mongodb-linux-2.4.1 tarball. Then I untar it. go to mongodb-linux-2.4.1/bin folder and start it by
./mongo
Then I got:
li#li-HP:~/Tools/mongodb-linux-x86_64-2.4.1/bin$ ./mongo
MongoDB shell version: 2.4.1
connecting to: test
Fri Mar 29 19:29:47.958 JavaScript execution failed: Error: couldn't connect to
server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
exception: connect failed
Any suggestion?
./mongo just run mongodb client
./mongod run mongodb server