Deploy Rails 4 with Dokku

  05 May 2014

Recently, dotCloud, a popular PaaS releases software which powers their infrastructure named “Docker”. It is very interesting and promising project.

Docker is basically a tool to manage LXC Linux containers, check out for more details. It provides fast and lightweight userspace for the linux kernel (as opposed to heavy weight Virual Machine implementation). In my visual perspective: Docker > LXC > Chroot

At the mean time there is a project named “Dokku” which tries to implement Heroku-like PaaS. And this article is about how to deploy Rails 4 using Dokku. I’m running Ubuntu 13.04 and let’s start installing Dokku. Just grab the stable version

wget -qO- | sudo DOKKU_TAG=v0.2.3 bash

It’s 0.2.3 at the time of writing, Add new SSH config, edit ~/.ssh/config

Host server-ip
    HostName server-ip
    User git
    IdentifyFile  ~/.ssh/id_rsa

Inside your project, add new remote

git remote add dokku dokku@server-ip:subdomain-or-appname

Then, add permission for your machine, so that you can git push to new remote

cat ~/.ssh/ | ssh user@server-ip “sshcommand acl-add dokku user”

Install relavant plugins, in this case is showing how to install Postgresql plugin

cd /var/lib/dokku/plugins
git clone postgresql && cd postgresql

After postgresql plugin installed, you can create the database by

dokku postgresql:create db-name

At this point, you are ready to deploy. Step inside your project and run

git push dokku master

And link database to the app

dokku postgresql:link app-name db-name

Restart nginx if needed.

/etc/init.d/nginx restart

If you use Procfile for the project and have worker job, you might want to check shoreman in order to start. Since current dokku will only start ‘web’ process type.

 git clone /var/lib/dokku/plugins/dokku-shoreman

On the next deploy, it will start worker process type as well.

In case your application have files upload functionality to local file system, you might find dokku persisten-storage plugin useful.

 git clone /var/lib/dokku/plugins/persistent-storage

You can mount a host directory as a container volume. For example, in your server

 cd /home/dokku
 mkdir -p shared/system


 touch /home/dokku/<app-name>/PERSISTENT_STORAGE
 echo  “/home/dokku/shared:/app/public:rw” > /home/dokku/<app-name>/PERSISTENT_STORAGE

Now your container will have mount point to host writable file system. Therefore, the app stores statics files in container /app/public but writes to /home/dokku/shared/system on host filesystem.


  1. If you’d like to have your app available on your subdomain make sure your hostname match with your app name and /home/dokku/VHOST contains your domain name.
  2. Use docker commands such as docker ps and docker images` are very useful command to trace some problems. I have created an uninstall script for convenience while testing.
comments powered by Disqus