How to Set Up and Configure Dokku on Digital Ocean

Learn how to install and set up Dokku on Digital Ocean as a convenient and budget-friendly way to deploy apps to DigitalOcean.

Picture of Nsikak Imoh, author of Macsika Blog
Image with the Text How to Set Up and Configure Dokku on Digital Ocean
Image with the Text How to Set Up and Configure Dokku on Digital Ocean

Table of Content

Dokku is a piece of open-source software that “helps you build and manage the lifecycle of applications”.

It uses Docker under the hood to create and run applications inside containers and supports Ubuntu 14.04/16.04, Debian 8.2, and CentOS 7 platforms with a very small team of core maintainers.

In this tutorial, you will learn how to install and set up Dokku on Digital Ocean as a convenient and budget-friendly way to deploy apps to DigitalOcean.

What is Dokku?

Dokku is a free and open-source tool for creating a personal docker-powered PaaS (Platform as a Service) that helps you build and manage the lifecycle of your applications easily.

If you are familiar with Heroku, you can think of it as your own self-hosted Heroku, but way cheaper.

Dokku can be installed on any hardware, which makes it super easy to manage your server.

How does Dokku Work?

Dokku installs Docker and then uses it to manage deployments of applications.

It allows you as a developer to push applications to it using Git.

Then it will build those applications for you, package them into a Docker container, and then manage the lifetime of that container on your behalf.

It will also automatically configure Nginx so that your application can be reached, with its virtual hostname support.

What is the Benefit of Dokku?

There are a lot of benefits that come with using Dokku, however, here are the top ones that resonate with us:

  • Dokku makes it super easy to create containers for each app in the terminal.

  • You can also create free SSL certificates with let's encrypt that are auto-renewed just before they expire.

  • Once you've set up your host, you can use Git to push your application to the server.

  • When you make an update to the application and push it to git, your container environment is torn down and recreated once again according to your configuration.

  • When used for deployment, Dokku supports zero-down-time deploys, as it can keep your old environment alive until the new one is fully built.

  • You can control Dokku through simple CLI commands or through a web interface using third-party libraries.

Disadvantage of Using Dokku

There is no official web interface for managing an application through a browser.

Everything is done via the command-line only.

For some people, that may be a turn-off.

However, to supplement this, Dokku CLI is very simple to learn using the Bash scripting language.

How to Set Up Dokku on Digital Ocean

1. Get an Account on DigitalOcean

To begin, you will be required to have an account with Digital Ocean.

If already have an account with Digital Ocean, you may skip this step, otherwise use the link: Digital Ocean to create a new account and receive $200 worth of credit for your project in the first two months!

While setting up your Digital Ocean account, you may be required to enter your card details for verification.

That said, we can move to the next step.

2. Create a New DigitalOcean Project

Once you have created your account, you can go ahead and create a new project from within the DigitalOcean dashboard.

Click “Create Project” in the menu and follow the instructions provided by DigitalOcean.

3. Set Up DigitalOcean Droplet in the Project

After creating a new project, we can go ahead and create a new droplet.

DigitalOcean Droplets are simply the name DigitalOcean calls the VPS instances.

It's just your server.

Fortunately, the DigitalOcean marketplace provides pre-configured versions of Linux Ubuntu and Dokku.

We can use this to save some valuable time, as it requires less server configuration.

You find it under the marketplace tab while searching for “Dokku”.

During the time of this tutorial, the current version of Dokku was 0.21.4 and the version of Ubuntu is 20.04.

Hence, the actual version numbers may vary when you follow this tutorial.

When you search, select “Dokku 0.21.4 on Ubuntu 20.04”.

Select a suitable region for the server.

Once you have selected a region suited for you, we can go ahead and select an SSH key that we want to associate with our new server.

We choose to authenticate via SSH keys as it is generally much more secure than using a one-time password.

4. Add your SSH key to DigitalOcean

When you got your SSH key at hand, you will have to open your DigitalOcean cloud dashboard and navigate to Settings > security or the URL cloud.digitalocean.com/account/security and click the button Add SSH Key.

Here is how you can create, access, and use SSH on Mac and Linux OS platforms.

5. Access the SSH of your droplet

Once your droplet has booted up, we can go ahead and open our terminal and SSH into the newly created droplet.

ssh [email protected]
Highlighted code sample.

Follow the instruction and choose yes if asked to add the host to the list of hosts on your computer.

The authenticity of host '123.456.789.10 (123.456.789.10)' can't be established.
ED25519 key fingerprint is SHA256:3W+tQ2oVlLr1Aqp+yf/XXXXXXXXXXXXXXXXXXXXXXX.
This key is not known by any other names

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Highlighted code sample.

If your authentication is successful, you will be greeted with the following prompt.

Warning: Permanently added '123.456.789.10' (ED25519) to the list of known hosts.
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-52-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Tue Oct  4 20:05:47 UTC 2022

  System load:  0.0                Users logged in:          0
  Usage of /:   16.2% of 24.06GB   IPv4 address for docker0: 172.17.0.1
  Memory usage: 28%                IPv4 address for eth0:    123.456.789.10
  Swap usage:   0%                 IPv4 address for eth0:    12.34.0.5
  Processes:    110                IPv4 address for eth1:    12.345.0.2

288 updates can be installed immediately.
176 of these updates are security updates.
To see these additional updates run: apt list --upgradable


********************************************************************************

Welcome to DigitalOcean's 1-Click Dokku Droplet.
To keep this Droplet secure, the UFW firewall is enabled.
All ports are BLOCKED except 22 (SSH), 80 (HTTP), 443 (HTTPS),
2375 (Docker) and 2376 (Docker).

In a web browser, you can view:
 * The Dokku 1-Click Quickstart guide: https://do.co/3nzKhrp#start
 * Your Dokku setup page: http://143.198.139.47

For help and more information, visit https://do.co/3nzKhrp

********************************************************************************
Highlighted code sample.

6. Update Dokku to the Latest Version

Update to the latest version of Dokku. We can install the latest version with wget.

wget https://raw.githubusercontent.com/dokku/dokku/v0.28.1/bootstrap.sh

sudo DOKKU_TAG=v0.28.1 bash bootstrap.sh
Highlighted code sample.

To make sure you are updating to the latest version of Dokku you can check the release page.

7. Configure Dokku

When the update is done, you can configure Dokku by navigating to our IP address in the browser (http://123.456.789.101).

Here you will be greeted with the Dokku setup page.

Verify that the SSH key is correct and add your domain name and click the checkbox to use virtual host naming for apps.

The next thing you need to do is decide whether to use virtual host naming for your apps.

If you opt to use virtual host naming for apps, your applications will be available at http://appname.yourdomain.com, and you can redirect individual apps to specific domains later.

Virtual host naming does not restrict you from serving your final application from the “appname” subdomain.

If you have a domain that you want to use (e.g. example.com), then you can turn on virtual host naming by ticking the box so that your apps are accessed as subdomains.

For example, creating an app called “Test” will mean that you will be able to access your application at http://test.example.com.

If you do not have a domain that you wish to use for your Dokku server, then you should leave this box unticked.

This will mean that your apps would become available on a specific port number, e.g. http://123.456.789.101:5000.

You will need to configure the firewall to open specific application ports.

I have a domain I'm going to use, so I will tick the box.

One thing you should know is that for this to work, you must configure your domain's DNS with an A record that points to your Dokku server.

In my example, I'm using a domain nsikakimoh.com with an A record of * that points to my server at 123.456.789.101.

This means that any traffic that goes to a subdomain e.g. http://test.nsikakimoh.com will be routed to my Dokku server and Nginx will route it to the correct place.

Also, note that changing your DNS settings may require a bit of time for the changes to fully take effect.

With that done, click “Finish Setup” to proceed. Your Dokku server is now ready to go!

Wrap Off

That's basically all there is to it.

If done correctly, you should have now installed Dokku on DigitalOcean and are now ready to start serving our docker-powered containerized applications.

If you learned from this tutorial, or it helped you in any way, please consider sharing and subscribing to our newsletter.

Please share this post and for more insightful posts on business, technology, engineering, history, and marketing, subscribe to our newsletter.

Connect with me.

Need an engineer on your team to grease an idea, build a great product, grow a business or just sip tea and share a laugh?