Production Meteor in 10 Minutes
Deploying meteor apps has historically been pretty hard. Getting SSL, Websockets and Sticky Sessions can be tricky.
Luckily with things like Docker and Caddy deploying production quality applications is getting easier.
I’m going to deploy Rocket Chat on a $5 Digital Ocean box and it’s going to have Websockets, Sticky Sessions, SSL and it’s going to take less than 10 minutes.
Minute 1: Digital Ocean Droplet
I’m going to provision an Ubuntu 16.04, $5, SFO-1 box.
Minute 2: Install Docker
SSH into your DO box and paste the following:
curl -fsSL https://get.docker.com/ | sh
This took about 1 minute to run
Minute 3: Add your DNS Records
I’m going to use the domain rocket-chat.paytagz.com (paytagz.com is a domain that I already own)
Just create a new A record pointing to your DO IP address (I use Route53).
Minute 4–7: Starting the Rocket Chat docker container
Rocket Chat comes with an official docker image which can be found here.
Go back to your terminal where your SSH’d in and create the Rocket Chat container like this:
docker run --name rocketchat \
-p 3000:3000 \
--env ROOT_URL=https://rocket-chat.paytagz.com \
--env MONGO_URL=mongodb://<your mongo here> \
-d rocket.chat
I cheated a little on this step because I already have a mongodb set up on compose.io (which I highly recommend for production meteor deployments because it’s so much easier than hosting your own DB).
So now you can visit your DO box’s IP address at port 3000 and you can see your application running.
Minute 8: Creating the Caddyfile
You will now have to create what’s called a Caddyfile. It’s basically an nginx.conf file that’s way easier to create and understand.
In your terminal create the Caddyfile
touch Caddyfile
Then edit it
vim Caddyfile
Yours should look something like this (replace my IP and domain with your own).
rocket-chat.paytagz.com {
proxy / {
policy ip_hash
websocket
transparent
upstream http://162.243.130.9:3000
}
Minute 9: Running Caddy in a container
Run the following command in the same directory as the Caddyfile you created above.
docker run -d \
-v $(pwd)/Caddyfile:/etc/Caddyfile \
-v $HOME/.caddy:/root/.caddy \
-v /etc/ssl/certs:/etc/ssl/certs \
-p 80:80 -p 443:443 \
khamoud/caddy
Now if I visit https://rocket-chat.paytagz.com I’ll see my rocket chat fully set up with Websockets, SSL, and Sticky Sessions.
If you want to learn how to dockerize your own meteor application you can check out my tutorials for dockerizing meteor below.
If you are looking for even easier docker hosting you should consider https://www.rompli.com ;)