localhost:27017 connection refused in Docker container

1,938 views
Skip to first unread message

Andrew Langhorn

unread,
Jan 22, 2015, 8:32:22 PM1/22/15
to mongod...@googlegroups.com
Hi,

I'm running MongoDB in Docker for a side-project, and am using the stackbrew image from the Docker registry, since it seems that's the most like an officially-supported image.

My Dockerfile is as below... Oh, and it might not be the tidiest Dockerfile you've ever seen, but I can get to that later on ;)
  • ADD ./mongo.conf ~/mongodb/mongo.conf
  • RUN mkdir -p ~/mongodb/data
  • ADD zips.json ~/mongodb/zips.json
  • RUN mkdir -p /var/log/mongodb
  • RUN touch /var/log/mongodb/mongodb.log
  • RUN chown mongodb:mongodb /var/log/mongodb/mongodb.log
  • EXPOSE 27017
  • RUN mongod --config ~/mongodb/mongo.conf
  • RUN mongoimport --verbose --db zips --collection zips --type json --file ~/mongodb/zips.json
~/mongodb/mongo.conf looks like:

systemLog:
destination: file
path: "/var/log/mongodb/mongodb.log"
logAppend: true

processManagement:
     fork: true

Forking allows me to keep MongoDB running in the background, and setting up a log is a prerequisite for daemonizing MongoDB.

When running this Dockerfile through docker build, I'm told that during mongoimport, a connection to 127.0.0.1:27017 is being refused. I've tried diagnosing this with some common tools, like lsof, netstat and a few others, but either I come across containerisation woes, or I get no meaningful pointers.

Oddly, there's no init scripts in /etc/init or /etc/init.d relating to Mongo, which made me think that it probably wasn't installing. But, if I run `mongo --version` and `mongod --version`, I get told 2.6.7 is in use, which is as expected.

Any advice appreciated!

Thanks,

--
Andrew Langhorn
Web Operations
Government Digital Service

a: 6th Floor, Aviation House, 125 Kingsway, London, WC2B 6NH

Ernie Hershey

unread,
Jan 22, 2015, 11:05:35 PM1/22/15
to mongodb-user
Hi Andrew,

Could mongoimport be running before mongod has time to open its listening socket? As a test, does it work if you add a "RUN sleep 10" between mongod and mongoimport? Can you post an execution log from running the container, including the error, and the mongodb.log from the same run? 

Ernie

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CANCa_WYqXepqMnhrOWRezKKcNjK5ir1Tqssqopp2qkspPhQ3nQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages