Easy application deployments with Dokku

The issue

So as a junior developer I haven't had much time to learn about hosting applications in a production environment. I'm used to deploying to heroku. Heroku makes it super easy to get applications online, no installing nginx by hand or anything like that. Really simple really great stuff.

But... This all comes at a hefty price starting at $34.50 for a 1GB "dyno"...

What would be really great is if I could host the app myself on a box somewhere in the cloud and deploy to it just like I do with heroku and git. Oh wait... you can.

Dokku - the resolution

Dokku is a "docker powered mini-heroku". I'm using Dokku-alt as it comes with a tonne more features, all are listed on the repo and in the command line.

Go ahead and spin up a server, I use Digital Ocean (use that link and you get $10 credit), They're fast, cheap and have loads data centers all over the world.

Once you SSH into your server run the install script thats on the github page.
sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/dokku-alt/dokku-alt/master/bootstrap.sh)" < /dev/null

Believe it not you're actually about 60% of the way done after this...

You'll notice eventually that it boots a Sinatra server. This is to configure the type of routing you your apps will have and to add a key. As I'm deploying to a production environment I'm going to make sure I have a wild-card subdomain. This way I can have my_app.example.com. Fill in the form and tick the box.

To get your key copy the output of cat ~/.ssh/id_rsa.pub on your local machine into the text box. Submit the form and then kill the Sinatra server on your VPS.


Yay! We're nearly at the point where we can just git push to deploy. Lets assume you're friendly with git, if not get friendly, sign up to something like Github and come back.

Thers actually a quick little tutorial on the Dokku page about deploying heroku's demo node app. As I'm a Ruby developer I'm going to deploy a Ruby on Rails app.

If you have deployed a Rails app to heroku before you will probably be familiar with unicorn. You can literally just follow the heroku tutorial there to get unicorn plummed into your app if you haven't already.
unicorn! Make sure you have a Procfile in the root of your app that has something similar to this inside web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb.

About 80% done so far ;)

Next, deployment. Add the server as a git remote git remote add deploy dokku@app_name.example.com:app_name

Do the usually git add -A, git commit -m "blah blah blah" and finailly deploy your app with git push deploy master and watch the magic happen.

Installing gems blah blah


90% Done...


As you are a good Ruby Rails dev you're using postgres like you should be ;).

All thats left is to install postgres, create a database and get rails talking to it.(All a lot easier with dokku).

SSH back into your server and run dokku postgresql:create app_name. Dokku will work out that PG isn't installed and will go away and do that for you.

After a couple mins it should come back and tell you that it has been created. Finally, link the DB to your app with dokku postgresql:link app_name db_name and migrate the database with dokku run api rake db:migrate.

Moment of truth...

If you've mamnged to follow along and keep up good for you. If not that sucks and google is your friend. Head to app_name.example.com and check out your app. If your getting errors and stuff at this point run dokku logs app_name -t to tail your apps logs and work out whats going on.


I do hope you were clever enough to change "app_name" wherever you saw it and didn't just mindlessly copy and paste like I do usually.

comments powered by Disqus