Install Dokku and deploy your Rails project with git

Published 30.9.2024

This time we’ll do a speedrun of installing Dokku on a remote server, deploying a Rails project with Postgresql and configuring a domain name. You should already have a remote server with Ubuntu 20.04/22.04/24.04 or Debian 11+ x64 for this.

Let’s go!

Installing Dokku

Ssh to your remote server and install Dokku using the Dokku install script:

ssh root@YOUR-SERVER-IP
wget -NP . https://dokku.com/install/v0.35.4/bootstrap.sh
sudo DOKKU_TAG=v0.35.4 bash bootstrap.sh

Once the installation is complete, you should configure an ssh key and set your global domain:

cat ~/.ssh/authorized_keys | dokku ssh-keys:add admin
dokku domains:set-global YOUR-SERVER-IP

Deploying your Rails project

Still on your Dokku host, create a new Dokku app:

dokku apps:create YOUR-PROJECT-NAME

Install the Dokku Postgresql plugin, create a database and link it to your project:

sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
dokku postgres:create railsdatabase
dokku postgres:link railsdatabase YOUR-PROJECT-NAME

Then, on your local development machine, go to your Rails project folder, set up the Git remote and push your code to your new Dokku instance:

git remote add dokku dokku@YOUR-SERVER-IP:YOUR-PROJECT-NAME
git push dokku main

Configuring your DNS settings for your domain

If you’ve just bought a domain name, you should delete the existing DNS records for the domain. What you’ll need, is a record with the following configuration:

Then go back to your server’s ssh session and run:

dokku domains:add YOUR-PROJECT-NAME YOUR-DOMAIN-OR-SUBDOMAIN-NAME

And the last thing is to remember to setup your Rails database and its migrations:

dokku run rails db:setup

That is all! Hope it worked!