Your Own Mini-Heroku on AWS

by

Mini heroku push


Heroku
is one of those really great tools to help you get started fast with hosting. They support a variety of stacks and save you blood, sweat and tears when it comes to deploying an app. But what about those times where you need to mess with filesystems or have custom binaries that you want to run? How about just having more control of your servers? Dokku to the rescue! Dokku is a small (just above 100 lines of code) yet very powerful tool based on Docker. Dokku utilizes Docker and Nginx plus some other candy to significantly simplify the process of deploying.

Advantages:

  1. More control, more access. Customize to your needs
  2. Unlimited projects (or at least however many your hard drives can keep)
  3. Cheaper, because lets face it; you get tired of waiting for that Heroku dyno to start up

Disadvantages:

  1. Doesn’t scale as easily
  2. Doesn’t necessarily have the guarantee of availability as Heroku (depends on server hosting)
  3. Still pretty fresh (but lots of new features in progress)

For now I think that Dokku is great for development, maybe as a staging server to be used within a company or for hobbyists. It is super fast to set up and allows you and your co-workers/friends to host apps simply. Dokku also saves you the time for setting up web servers and configurations in the case you just want to host your own apps.

Below is a couple of fast steps in order to get started with Dokku on AWS. In this tutorial we will set up a sample Node.js app using Sailsjs. We assume you already have access to AWS.

  1. What we first need is a server instance to run Dokku. As the time of this writing there are some issues with Ubuntu 13.10 and it’s recommended to run Ubuntu 13.04 for Dokku. The AMI for Ubuntu server 13.04 x64 can be found here:
    https://console.aws.amazon.com/ec2/home?region=us-west-1#launchAmi=ami-3cf1c179
  2. Once the instance is up and running, we need to allow port 80 for our instance. This can be done under “Security Groups” in the AWS console.
  3. Now that we have the server up and running go ahead and point any top level domain to this instance. The ip of the instance can be found in the AWS console in the description for your instance (Public IP).
  4. Next thing to do is to ssh into your new Ubuntu 13.04 server and install Dokku (which automatically installs all dependencies and sets everything up for you):
    ssh -i ~/.ssh/aws.pem ubuntu@my.com
    wget -qO- https://raw.github.com/progrium/dokku/v0.2.1/bootstrap.sh | sudo DOKKU_TAG=v0.2.1 bash
  5. When the installation is done, run the following command to set your hostname:
    echo "my-domain.com" > /home/dokku/VHOST
  6. We now need to add our public key to be able to push to our Dokku server.
    cat ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/aws.pem ubuntu@my-domain.com "sudo sshcommand acl-add dokku dokku”
  7. Next let’s generate an application and push it to see if it works!
    npm install sails -g #Install sails if you haven’t got it yet
    sails new myapp
    cd myapp
    echo "web: node app.js" > Procfile
    git init .
    git add . -v
    git commit -m "Initial commit, cross your fingers that this will work!"
    
  8. At this point we have a server running on AWS, with dokku running on it. We have generated a brand new app using Sailsjs and we have added necessary Procfile to make it run on our server. We now need to add the remote and then deploy:
     git remote add mini-heroku dokku@my-domain.com:myapp
     git push mini-heroku master
    

That’s it! In 8 simple steps (with hopefully a lot of coffee breaks) you have set up your own mini-Heroku!

2 Comments

    • The Nginx is used a proxy to route basically “route” the apps. Your DNS *.domain.com needs to point to your dokku server. Nginx lies in the front proxying the request to the right application server. Example: User browses to –> app123.domain.com:80 –> Nginx on port 80, realizes it’s a request for app123 –> proxies to localhost:3000 (or whatever port it chose to run this particular app on).

      Looking into the source code, it seems Dokku is for Ubuntu or any distro with an apt based package manager. I base that on the way it installs the dependencies (using apt). Not sure how well it would work with any other similar distro, but given the recommendations in the documentation it seems your better off keeping to a specific Ubuntu version (13.04)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>