2

I am trying to deploy a Meteor application to my Ubuntu 14.04 (Trusty Tahr) VPS. I am using a private Docker registry on DockerHub, with an automated build setup pulling from my Git repository on Bitbucket. That works really well.

However, when I run my container I am not able to see the Meteor app running. I have read about phusion-passenger and Meteor in their documentation, but I think the guide is missing something, as I cannot get it to work.

My approach has been to use meteor to create an application:

meteor create simple-wishes

This creates a directory with a CSS, HTML and JavaScript file inside (and a .meteor folder). Outside this directory I have created a Dockerfile, looking like this:

FROM phusion/passenger-nodejs:0.9.14
MAINTAINER Søren Pedersen

# Set correct environment variables.
ENV HOME /root

# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]

# ssh
ADD ssh/id_rsa.pub /tmp/your_key
RUN cat /tmp/your_key >> /root/.ssh/authorized_keys && rm -f /tmp/your_key

# install meteor
RUN curl https://install.meteor.com | /bin/sh

# Remove the default site
RUN rm /etc/nginx/sites-enabled/default

# Enable nginx
RUN rm -f /etc/service/nginx/down

# Setup app
ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf
RUN mkdir /home/app/simple-wishes
ADD simple-wishes /home/app/simple-wishes

The webapp.conf file referenced in the Dockerfile looks like this:

server {
    listen 80;
    server_name simple-wishes.com;
    root /home/app/simple-wishes/public;

    passenger_enabled on;
    passenger_user app;
    passenger_sticky_sessions on;
    passenger_set_cgi_param MONGO_URL mongodb://localhost:27017/meteor;
    passenger_set_cgi_param MONGO_OPLOG_URL mongodb://localhost:27017/local;
    passenger_set_cgi_param ROOT_URL http://simple-wishes.com;

    # Set these ONLY if your app is a Meteor bundle!
    #passenger_app_type node;
    #passenger_startup_file main.js;
}

On my VPS I run a container like this:

docker run -d -p 80:80 -p 2200:22 sohape/simplewishes

This pulls the image from DockerHub and starts the container in daemon mode, mapping port 80 and 22 to port 80 and 2200 on the host.

When I make an HTTP request to the server now (http://simple-wishes.com), I get an error from nginx:

502 Bad Gateway

I must be missing some step here, but I cannot figure out what. So I hope someone can point me in the right direction.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Søren Pedersen
  • 764
  • 8
  • 20

3 Answers3

0

Local host inside your Docker container is not the same localhost outside. You may want to use --link to link the containers if MongoDB is in its own container or uses a well-known DNS entry.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Usman Ismail
  • 17,999
  • 14
  • 83
  • 165
  • That is a good point! - but in this case mongo is in the same container - meteor should be spinning up a mongo instance automatically. So I think localhost is correct – Søren Pedersen Nov 06 '14 at 08:06
0

When you run Meteor as you are without bundling your application, Meteor will spin up a MongoDB instance, but not on the default MongoDB port.

Check the answer to Stack Overflow question How do I use the existing MongoDB in a Meteor project?.

Community
  • 1
  • 1
0

You could try using my Docker image and see how it is set up. To quickly run it, use the following command (make sure to make a bundle of your Meteor application first):

docker run -d \
    -e ROOT_URL=http://yourapp.com \
    -e MONGO_URL=mongodb://url \
    -e MONGO_OPLOG_URL=mongodb://oplog_url \
    -v /dir_containing_bundledir:/home/app/webapp \
    -p 80:80 \
    joostlaan/meteor-docker-passenger

You can see how I built it at GitHub.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joost van der Laan
  • 2,536
  • 1
  • 18
  • 10