paint-brush
Build a Free Personal Heroku with Oracle Cloud and Dokkuby@rremedio
1,495 reads
1,495 reads

Build a Free Personal Heroku with Oracle Cloud and Dokku

by Roberto RemedioSeptember 26th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

How to do install Dokku, a free, self-hosted, alternative to Heroku, on an Oracle Cloud VM, step by step.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Build a Free Personal Heroku with Oracle Cloud and Dokku
Roberto Remedio HackerNoon profile picture

Heroku is one of the most beloved companies on the internet for me and for many others. However, many feel orphaned due to their decision to terminate their free products.


Some other free or cheap services can replace part of Heroku’s free products, but what about having your own hosting solution for your apps on the cloud for free?


I'm going to show you how to do that by installing Dokku, a free, self-hosted, alternative to Heroku, on an Oracle Cloud VM, step by step.

Requirements

  • An Oracle Cloud account. Oracle offers, at the time of this writing, two free VMs per user. It can be a trial account or a standard one. We are only going to use free resources.
  • git with ssh keys installed;
  • An app you can deploy to Dokku (something you would deploy to Heroku);
  • A domain you own (we are going to call it <your-domain-name>);
  • A drink and a snack.

1  -  Creating the VM

  • Go to Compute → Instances, click Create Instance. Give it a name.

  • Go to Image and Shape.
    SelectCanonical Ubuntu, version 18.04for the image.
    For the shape, selectVM.Standard.E2.1.Micro;

  • Go to Networking.
    Select the existingPrimary Network and Subnet. Create one if you don’t have one already.
    ChooseAssign Public IP Address;

  • Go to Add SSH Keys.
    Either generate a key pair (requires installing them on your system), upload or paste your own public key;

  • Click Create. Wait until the VM finishes provisioning (the orange box turns to green);

  • On the VM page, click on the link to your subnet (Primary VNIC section);

  • Click on the Default Security List on the Security Lists panel;

  • Check if there are Ingress Rules for ports 80 and 443 (likely not);

  • Create an Ingress Rule with the following settings:


Stateless: CheckedSource

Type: CIDRSource

CIDR: 0.0.0.0/0IP

Protocol: TPCSource

Port Range: leave blank

Destination Port Range: 80,443

Description: HTTP(s)

2 - Installing Dokku

  • Now return to the Instances page and copy your VM's Public ID (we are going to call it <public-ip> from now on);

  • Open a terminal;

  • SSH into the VM with ssh ubuntu@<public-ip> (if asked if you want to continue, type yes);

  • Run the following commands (depending on when you are doing this, it may be wise to check Dokku’s website for updated commands):


    wget https://raw.githubusercontent.com/dokku/dokku/v0.28.1/bootstrap.sh
    sudo DOKKU_TAG=v0.28.1 bash bootstrap.sh
    


  • Wait while Dokku is installed, this will take around 5 to 8 minutes;

  • Open your ssh public key on a text file (or on the terminal) and copy its contents. Let's call them <CONTENTS_OF_ID_RSA_PUB_FILE>. Then run the next command:

    echo '<CONTENTS_OF_ID_RSA_PUB_FILE>' | sudo dokku ssh-keys:add admin

3 - Setting up Global Domains

Remember <your-domain-name> that we talked about? It's the domain you are going to use as the global domain for your Dokku installation. Now run the following commands:


dokku domains:clear-global
dokku domains:add-global <your-domain-name>


Now may also be a good time to set up your domain's DNS fields. I'm using Namecheap and I just had to create two A fields (* and @) pointing to <public-ip>.

4 - Creating your first app

We are going to create our first app on Dokku and deploy it from our local computer. I'm using a basic Sinatra app, but you can use any technology supported by Dokku (Rails, Django, Node, PHP. The list goes on). I'm gonna call this app Starter. You can use any name you want (let's call it <your-app-name>. Run the following command:


dokku apps:create <your-app-name>

5 - Deploying your app

Depending on the stack you are using, there may be different requirements for your deployment. In my case, I'm using Sinatra so I need to have a config.ru file or a PROCFILE. You may also need (and want even if not needed) to install buildpacks (you can use Heroku's buildpacks which are open source). Please check Dokku documentation about that.

With a terminal in your project folder, setup git:


git init
git add .
git commit -m "create app"
git remote add dokku dokku@<public-ip>:<your-app-name>
git push dokku master


The app will be created with the default subdomain of <your-app-name>.<your-domain-name>. For instance: if your app is called starter and your domain example.com, the app domain will be starter.example.com. But you can point your domain name directly to the app with the command dokku domains:add <your-app-name> <your-domain-name> (in our case: dokku domains:add starter example.com). That way our app would be visible directly on example.com.

6 - Accepting web requests on your VM

Opening the ports on the network isn't enough. You need to enable web traffic on the VM's iptables (at least for Oracle Cloud’s version of Ubuntu 18.04):

sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -F

7 - Enabling SSL with Letsencrypt

Run the following commands:


sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
dokku config:set --no-restart <your-app-name> DOKKU_LETSENCRYPT_EMAIL=<your-email-address>
dokku letsencrypt:enable <your-app-name>


If you run into errors you may want to try sudo service docker restart and retry dokku letsencrypt:enable <your-app-name>

And now your app should be up and running on https://<your-app-name>.<your-domain-name>

The End

And that's all for now. You should be able to run one reasonably sized app on this VM or multiple smaller apps. You can install buildpacks for databases (like Postgresql) and connect your apps to them. Oracle Cloud provides two free VM.Standard.E2.1.Micro VMs so you can play a little bit with it.

Of course, if you consider using this kind of hosting for serious apps, you will probably want to go with a stronger VM and robust services around it.

Sources / Further Reading