Skip to content

Instantly share code, notes, and snippets.

@djmbritt
Forked from ungoldman/dokku_setup.md
Created April 16, 2014 22:10
Show Gist options
  • Save djmbritt/10938092 to your computer and use it in GitHub Desktop.
Save djmbritt/10938092 to your computer and use it in GitHub Desktop.

Deploy your own PaaS!

Setting up Dokku with DigitalOcean and Namecheap

..or how I made my own heroku in a few hours for $3.98.

This write-up owes a great deal to dscape's Node.js Deployments with Docker, Dokku, & Digital Ocean, the dokku project itself, and the fine folks working on dokku's issues. I took dscape's article as a starting point when trying this out but found some details lacking so I documented my own process for getting dokku up and running.

1. Get a domain

Make sure you have a domain picked out first. There will be less waiting around for the DNS to resolve. I got http://valis.pw from namecheap for a cool 3.98/yr.

2. Create a droplet

Sign up for DigitalOcean if you haven't already. I used a promo code and got $10 credit, effectively getting two months for free if I keep my usage low enough to only need a 512mb instance.

As of 2013-11-03T04:01:13.102Z dokku is having issues with Ubuntu 13.10, so go with Ubuntu 13.04 x64 unless that issue's been resolved. Make sure the droplet's hostname is the exact same as your domain (mine would be valis.pw), as this will ensure /etc/hostname and the hostname command respond correctly (something dokku relies on).

3. Configure DNS

Once the droplet is up and running you should have an IP address to work with. If you're using namecheap, go to the "All Host Records" page of namecheap's "My Account > Manage Domains > Modify Domain" section.

You'll need an A record for the naked domain (the "@" one) pointing to your IP with the lowest TTL possible (namecheap caps the minimum at 60), and a wildcard for subdomains with the same info. I'd recommend redirecting www to the naked domain.

It should look something like this when you're done entering your data.

HOST NAME IP ADDRESS/URL RECORD TYPE MX PREF TTL
@ your.ip.address.k.thx A (Address) n/a 60
www http://your.domain URL Redirect (301) n/a 60
* your.ip.address.k.thx A (Address) n/a 60

4. Bootstrap Dokku

Once you get a happy response from dig +short $HOSTNAME (where $HOSTNAME is your hostname, e.g. dig +short valis.pw, and the response contains the IP address you got from Digital Ocean and set in your Host Record configuration), you should be ready to go.

If you set up your SSH keys correctly you should be able to simply connect to the droplet via ssh without a password.

ssh root@your.domain # or root@your.ip.address.k.thx

For me the command was ssh root@valis.pw. I immediately checked if /etc/hostname contained valis.pw and the hostname command responded in kind just to be sure.

Once you're logged in as root, you can simply run the dokku bootstrap script.

wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash

5. Configure Dokku

cat ~/.ssh/id_rsa.pub | ssh root@your.domain "sudo sshcommand acl-add dokku $NAME"

In this case dokku is the user associated with the dokku command (already created by dokku's bootstrap.sh), so it should not be changed. The $NAME parameter is the name of the SSH key you're adding (so that it can be removed later by name if necessary). $NAME should be changed (might be a good idea to use the name you gave to the same SSH key on Digital Ocean).

6. Deploy an App to a subdomain

Choose an app you want to deploy, cd into the repo, and add a new remote like so:

git remote add dokku dokku@your.domain:your-app-name

In my case I ran git remote add valis dokku@valis.pw:pedestrian followed by git push valis master to deploy a dummy application to http://pedestrian.valis.pw. It worked!

Don't forget that your app still needs to conform to whatever the buildpacks are expecting. For example, a node.js app needs a package.json file listing dependencies to install and a Procfile specifying what processes to run.

7. Deploy an App to the root domain

This is detailed on this page of dokku's github wiki (took a little searching to actually track this down).

Basically all you need to do is make the part of the git address after the colon the same as the root domain.

git remote add dokku dokku@your.domain:your.domain

So for my setup, I'm doing git remote add valis dokku@valis.pw:valis.pw to deploy a very basic Node.js app (source). Though it's not explicitly stated in the wiki, this will work for any domain as long as that domain's A Record is pointing at your droplet's IP. Dokku takes care of setting up the vhost for you, so once it's done building, it should just work.

Victory Lap

Feelin pretty cool right about now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment