1
votes

Meteor works perfectly if I run "meteor". If I setup MongoDB and run Meteor with MONGO_URL set to "mongodb://127.0.0.1:27017/meteor" then it too works perfectly. However, if I run a Docker Container that calls exactly the same Meteor files on the same machine with the MONGO_URL set as above then I get the error: "Exception in callback of async function: Error: failed to connect to [127.0.0.1:27017]". Logic would state that the introduction of Docker is causing the problem. Therefore, is there something I must do to specifically allow Meteor to call MongoDB from inside a container - such as something additional with the MongoDB ports etc.

Dockerfile is:

FROM ubuntu:14.04 

MAINTAINER Me "[email protected]" 

RUN apt-get update -y && apt-get install --no-install-recommends -y -q chrpath libfreetype6 libfreetype6-dev libssl-dev libfontconfig1 

RUN apt-get install --no-install-recommends -y -q build-essential ca-certificates curl git gcc make nano python 

ENV PATH /bin:/usr/local/sbin 

RUN curl install.meteor.com | sh 

ENV ROOT_URL 127.0.0.1 
ENV PORT 3000 
ENV MONGO_URL mongodb://127.0.0.1:27017/meteor 

EXPOSE 3000 

CMD [ "meteor" ] 

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 

Meteor is called with the following:

docker run --name meteor-dev -it -p 3000:3000 -v /machine/meteor:/opt/meteor -w /opt/meteor meteor-dev 
1
Meteor is called with the following: docker run --name meteor-dev -it -p 3000:3000 -v /machine/meteor:/opt/meteor -w /opt/meteor meteor-devDavid Cittadini
Dockerfile is: FROM ubuntu:14.04 MAINTAINER Me "[email protected]" RUN apt-get update -y && apt-get install --no-install-recommends -y -q chrpath libfreetype6 libfreetype6-dev libssl-dev libfontconfig1 RUN apt-get install --no-install-recommends -y -q build-essential ca-certificates curl git gcc make nano python ENV PATH /bin:/usr/local/sbin RUN curl install.meteor.com | sh ENV ROOT_URL 127.0.0.1 ENV PORT 3000 ENV MONGO_URL mongodb://127.0.0.1:27017/meteor EXPOSE 3000 CMD [ "meteor" ] RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*David Cittadini
Sorry about the messy Dockerfile but it is the only way they will let me post so I thought something was better than nothing...and I see that this field has ruined my ROOT_URL reference anyway :)David Cittadini

1 Answers

4
votes

When you are running a container it creates its own network which is isolated from host network. So when you are tying to connect to Mongo using "mongodb://127.0.0.1:27017/meteor it searches for MongoDB inside your container.

Instead of using 127.0.0.1 use the host ip addresss or hostname.

Or if your MongoDB is running from a container create a link and use the link to start meteor container. Hope this helps