need help connect to mongodb from local to container

606 views
Skip to first unread message

Isaac Chen

unread,
Sep 8, 2015, 4:49:30 AM9/8/15
to mongodb-user
Hi everyone I got a problem needed to be solved:
I'd like to connect to mongo db  which is built in container.
process:
1. I build mongo constructed by official, but version is 2.4.9.  the attachment is my dockerfile
2. Everytime, I run container I need to do "sudo service mongodb restart"(this is part I still get why?)
3. After that mongo is set
4. edit /etc/mongodb.conf file, based on internet information, modify bind_ip = container i address from ifconfig , port=27017
5. mongo "container ip address" , failed. 

bug informed 

Error: couldn't connect to server x.x.x.x:27017 (x.x.x.x), connection attempt failed

    at connect (src/mongo/shell/mongo.js:181:14)

    at (connect):1:6 at src/mongo/shell/mongo.js:181


hope everyone could help!

thx very much!
Dockerfile.txt

Isaac Chen

unread,
Sep 8, 2015, 11:19:33 PM9/8/15
to mongodb-user

Thx a lot, I find out another method to achieve the goal although I did not understand why.

The step list below:
1. apply the dockerfile to install ubuntu and mongodb for the image
2. docker run -ti --name web testmongo:latest /bin/bash
3. vim /etc/mongodb.conf and set bind_ip=0.0.0.0 
4.cd /data && chmod -R 777 /data/db && chown uR mongodb:mongodb db
5. sudo service mongodb restart
DONE!!!
We can connect to container's mongodatabase in the host ubuntu 1404 .

------------------------------------------------the end -----------------------------------------

Dockerfile.txt
Reply all
Reply to author
Forward
0 new messages