Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Deploy Rails 4 app with Dokku on DigitalOcean

Deploy Rails 4 app with Dokku on DigitalOcean

Install dokku

First create a Ubuntu 13.04 x64 droplet on DigitalOcean Control Panel

Then ssh with root account, run this in termianl:

$ wget -qO- | sudo bash

Config dokku

$ cat ~/.ssh/ | ssh root@ "gitreceive upload-key dokku"

$ git remote add dokku git@[SERVER_IP_ADDRESS]:[APP_NAME]

Deploy Rails app

Add gem 'rails_12factor' to Gemfile

Then install dokku PG plugin:

cd /var/lib/dokku/plugins
git clone postgresql
dokku plugins-install

Create app database

root@mg-dokku:~# dokku postgresql:create [APP_NAME]

Then $ git push dokku master to deploy.

When it finished, run $ docker ps -a to show status:

root@mg-dokku:~# docker ps -a
ID                  IMAGE                  COMMAND                CREATED             STATUS              PORTS
290ae95c5ae7        app/mg:latest          /bin/bash -c /start    3 minutes ago       Up 3 minutes        49153->49153
1b79bc29ae77        postgresql/mg:latest   /usr/bin/start_pgsql   6 minutes ago       Up 6 minutes        49156->5432

But we have not run database migrations yet. Let's do it:

root@mg-dokku:~# docker run -i -t app/mg /bin/bash
root@085f103bec8a:/# cd app/
root@085f103bec8a:/app# RAILS_ENV=production rake db:migrate
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0

It fails, we try another way:

root@mg-dokku:~# docker run app/mg /bin/bash -c "cd /app ; rake db:migrate"
rake aborted!
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0

Fails too. :(

Here's a workaround:

root@085f103bec8a:/app# export HOME=/app
root@085f103bec8a:~# for file in /app/.profile.d/*; do source $file; done
root@085f103bec8a:~# hash -r
root@085f103bec8a:~# cd /app
root@085f103bec8a:~# RAILS_ENV=production rake db:migrate
==  DeviseCreateAdmins: migrating =============================================
-- create_table(:admins)
   -> 0.0125s
-- add_index(:admins, :email, {:unique=>true})
   -> 0.0034s
-- add_index(:admins, :reset_password_token, {:unique=>true})
   -> 0.0039s
==  DeviseCreateAdmins: migrated (0.0229s) ====================================

==  CreateCustomers: migrating ================================================
-- create_table(:customers)
   -> 0.0079s
==  CreateCustomers: migrated (0.0087s) =======================================

==  AddDeviceTypeToCustomers: migrating =======================================
-- add_column(:customers, :device_type, :string, {:default=>""})
   -> 0.0068s
==  AddDeviceTypeToCustomers: migrated (0.0075s) ==============================

Then visit http://[SERVER_IP_ADDRESS]:49153


Config Nginx

location / {
  proxy_pass        http://localhost:49153;
  proxy_set_header  X-Real-IP  $remote_addr;

This comment has been minimized.

Copy link

@cpursley cpursley commented Sep 7, 2013

Thanks for the Gist.

Stupid question, but I've gotten as far as http://[MY_SERVER_IP_ADDRESS]:49153 which works and is live. But how do I set my DNS to point at this address? It won't accept a ":" character? Is there something else I need to do from the command line to configure my DNS with Dokku?


This comment has been minimized.

Copy link
Owner Author

@linjunpop linjunpop commented Oct 14, 2013

Sorry @cpursley, github did not send any notification for gist comments. I think you need to config a web server(ex. nginx) to proxy request to port 49153.


This comment has been minimized.

Copy link

@yassotreyo yassotreyo commented Jun 14, 2014

Thanks for the gist, regarding the migration I just ran 'dokku run [APP_NAME] rake db:migrate' and it worked fine for me. The only problem I had with this : at the end, nginx doesn't serve my compiled static assets from the public directory, I think I will use S3 for that as mentioned in dokku/dokku#372.


This comment has been minimized.

Copy link

@sangyongjung sangyongjung commented Oct 2, 2014

Hi, I used to follow the workaround for migration and found another (easier way) for that.
Thought you might be interested in it. :)

근데, 한국분이신가요??


This comment has been minimized.

Copy link

@Xiangshen-Meng Xiangshen-Meng commented Sep 9, 2015

I solve the migration problem by running the "dokku run xxx rake db:migrate" from local. And I installed dokku client first. This maybe help :

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