Migrating From Heroku To Dokku

I decided to start using Dokku rather than Heroku. I’m going to skip my reasoning for maybe another time. Today I just want to share a run-through of the steps involved. It’s surprisingly easy.

So first, build and boot up an Ubuntu 16.04 machine. I chose Linode as my VPS provider. I like their prices. `nuff said.

To install Dokku, ssh into your new machine and enter the following commands:

wget https://raw.githubusercontent.com/dokku/dokku/v0.8.2/bootstrap.sh;
DOKKU_TAG=v0.8.2 bash bootstrap.sh

Create a dokku app, install the postgres plugin and link the db to the app:

dokku apps:create your-app-name
dokku plugin:install https://github.com/dokku/dokku-postgres.git
dokku postgres:create rails-database
dokku postgres:link rails-database your-app-name

To deploy the app, from your local machine, you need to add a new git remote, and then push to that remote. The commands will look something like the following:

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

I unfortunately ran into a timeout issue when deploying. On the server, you may have to use the following commands before your deploy will be successful:

dokku config:set --global CURL_TIMEOUT=600
dokku config:set --global CURL_CONNECT_TIMEOUT=30

Now, to setup SSL for your shiny new app, use the dokku-letsencrypt plugin. On the server, you’ll use the following commands:

dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
dokku config:set --no-restart myapp DOKKU_LETSENCRYPT_EMAIL=your@email.com
dokku letsencrypt myapp

Setting up SSL has never been so easy!

To migrate your data from Heroku to Dokku. From your local machine, type the following:

heroku pg:backups capture --app your-app-name
wget `heroku pg:backups public-url --app your-app-name`
scp your-pg-backup-file root@yourlinodehost:~/

Now, back on the server, type:

apt install postgresql-client-common
dokku postgres:import rails-database < pgbackup


And that’s it! It’s crazy how quick and easy it is. Your app should be up and running now. Cheers!