The Ultimate Digitalocean Dokku Deploy Guide (Rails & other environemnts).

Introduction

Hey everybody! Today, i want to share a guide i made on how to setup a Droplet on Digitalocean and also how to push your Rails project unto it.

If you are not familiar with Dokku and what it doees: It’s pretty much like Heroku. It’s a minimalistic deployingtool that allows you tocreate containers just via the local terminal, very similar to what we can do in Heroku.

So why Digitalocean and Dokku instead of Heroku? The answer is: Pricing. Digitalocean is much cheaper while also giving you much more freedom in choosing the right tier for your project. The downside of that is that you need to take care of your app on your own, while Heroku does this pretty much for you.

But don’t worry: It’s nothing you can’t learn. And the more you know, the better you become at the end of the day. It’s just like developing apps: You have to practice and learn how specific things work and you’ll be able to manage your app in a very short period of time.

Digitalocean also constantly updates their functions and they lately added also an automatic backup system that you can additionally add whenever you create a new droplet.

Digitalocean also offers lately also additional monitoring tools, making it easier as ever before to manage and monitor your app performance.

Step 1: Sign up on Digitalocean and create a new Droplet

In order to be able to follow this guide, you need an Digitalocean account (which is free) and a droplet. The most cheapest droplet you can get is the one for 5$ per month. Don’t worry, you can’t cancel your droplet on a monthly base, so with that you will pay at most 5$. From my experience, if you cancel your droplet after, let’s say, 2 days after you have deployed it, you will be only charged the amount it was online, so much less than the 5$. The 5$ will be in this case on your credit and can be used for another droplet you might create.

Here is a promo code from me, where you get some extra credits completely for free: https://m.do.co/c/b09b8801db13

After you have signed up, you can create a new droplet by clicking on “Create” in the Navbar and then choose “Droplets”

Next, you need to choose Dokku as an Image for your Droplet. If you can’t see it, click on “Marketplace” inside the Tabbar and choose “Dokku”

As a plan, we will use the “Standard” and then the “5$” Droplet (Click the left or right arrow if you can’t see it)

As for the server region, choose one that fits your interest the best.

And then finally, we need to add an SSH key.

SSH Keys are basically encrypted passwords, that we can use to sign in to our droplet later one inside our terminal. Without it, you won’t be able to sign in. There is also the other method to use your Email Adress, but it’s not very secure and i want to show you the “right” way, because later on, when you use your droplet in production, you want to use definitely the SSH method.

Luckily, Digitalocean makes it really easy to add a new SSH key. Click on “New SSH Key” and it will open up a new modal.

So how do we get a new SSH key? It’s easy. On the right sight, Digitalocean offers you a Quick Guide on how to do it.

To create a new SSH Key, open up your terminal and type in:

ssh-keygen

which will print:

Generating public/private rsa key pair. Enter file in which to save the key (/Users/USER/.ssh/id_rsa):

Just hit enter when it asks you for a file name.

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

Here you have to add a password. This password will be then encrypted. Use one that is easy to remember, but also secure at the same time.

Now, you can copy your SSH key via:

And paste it inside the SSH keyfield on the Digitalocean modal.

Click on “Add SSH Key”

Make sure, that you have “Select All” checked.

As for the Droplet numbers, choose 1. The hostname doesn’t matter, but you could rename it to a more simple hostname. I called mine “MediumTutorial”.

Finally, create a new droplet by clicking the “Create Droplet” button.

Digitalocean will now generate a new, fresh droplet for you and this might take a while. You should be already seeing your droplet being initialized:

Once it’s finished, you can click on your Droplet, this will take you to your Droplet dashboard:

The last step we need to do, is to activate our droplet finally. To do so, visit your ipv4 address via a new tab inside your browser:

Once you are able to visit your Droplet via ip4v address, you will see this (i didn’t took a screenshot from my ssh key, as it allows any one to access my droplet. Never share it!)

Here you can also rename your Hostname (recommended) to something easier to read and remind, as it will also effect your url (as you can see below).

Once you have done this, click on “Finish Setup” and boom!

Your droplet is now ready for deployment!

Step 2. Adding your GitHub repo to your newly created fresh droplet.

So your Droplet is now ready to go. You can sign in to your droplet by opening your terminal and typing in:

ssh root@your_ipv4_address

This will ask you for your SSH password.

Type in the SSH password you have used to create a new SSH key a few minutes ago.

Once you have entered the correct password, you will see the following:

Awesome! Now you are connected to your Droplet via your terminal.

Let’s create a new Dokku app. You can read more about Dokku here: http://dokku.viewdocs.io/dokku/getting-started/installation/

To create a new Dokku app, type in:

We also need a database for our Droplet. I use for Rails PostgreSQL, so lets run:

This will download the postgres plugin from Git on your Dokku Droplet! Nice!

Now, let’s create a new fresh database on our droplet:

The name of the database will be in this case “railsdatabase”. It’s up to you how you want to call your database.

Now, we need to connect the database to our app inside Dokku:

The first name is always the name of your database, the second the one of your app inside Dokku you just created a few seconds ago.

Now we are ready to push our GitHub repo to our Dokku Droplet.First, type in “exit” to leave your Dokku droplet environment.

Then, once your logged out of your Dokku droplet inside your terminal, cd into your local project you want to push.

Then, add a new git remote:

The app_name is the name you have given your GitHub repository.

Now, simply run:

This will ask your again for your SSH password. Type it in and it will deploy, just like on Heroku, your app to your droplet.

Once that is finished, you need to add an domain to your dokku app.

To do so, simply log into your dokku droplet, and type in:

this will give you all existing, current domains on your dokku. There should be none.

To add a new domain, type in:

this will add the vHost domain of “test” to your app.

You can always remove it later one.

Now, with that, you should be able to visit your app by typing in the ipv4 address inside your browser.

Simply go to your dashboard and click on the … dropdown and choose “Destroy”:

Simply follow the instructions to delete your droplet completely (this will delete everything, your app, database and the complete droplet).

You can also always monitor your current billing by going to

Account->Billing on the left Navbar.

Keep in mind that it takes up to 1 day to see your billing being applied.

Liked it? Make sure to leave a comment, clap it and check out my YouTube channel where i constantly upload fresh web development content:

The next step from here would be to add a real domain to your droplet and to get a SSH certificate, via letsencrypt for example.

But since this relies a lot on the domain provider you use, i won’t get into it on this guide i suggest you to check out other guides specially made for this or the official Digitalocean Guide, which covers pretty much all major domain providers.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store