You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

Dokku is an extensible, open source Platform as a Service that runs on a single server of your choice. If you ever used Heroku, then think of it as your hosted version of Heroku. You can have docker based Platform as a Service running on a single server. In this guide, we will cover the installation of Dokku PaaS on Ubuntu 20.04|18.04 Linux System.

As of this article update the supported operating systems are:

  • Ubuntu 16.04/18.04/20.04 x64
  • Debian 9+ x64

With CentOS 7 still experimental

Installing Dokku on Ubuntu – Pre-requisites

  • Installed and updated Ubuntu 20.04|18.04 system
  • Docker Engine
  • At least 1GB of system memory
  • Server with FQDN set – Can be on DNS or /etc/hosts

There are two ways of installing Dokku on Ubuntu 20.0418.04:

  1. Using bootstrap script
  2. Installing from Dokku apt repository

We will consider both methods to install Dokku on Ubuntu 20.04|18.04 Linux server. I recommend installing Dokku from the apt repository so that you can have a view of what’s happening.

Set system hostname using the hostnamectl command:

$ sudo hostamectl set-hostname dokku.computingforgeeks.com

Ensure your system is updated and upgraded:

sudo apt update
sudo apt upgrade -y
sudo reboot

Method 1: Install Dokku on Ubuntu 20.04|18.04 from apt repository

Dokku packages are available on packagecloud.io dokku repository. Start by importing repository GPG key to trust packages:

sudo apt update
sudo apt install -y apt-transport-https
wget -nv -O - https://packagecloud.io/dokku/dokku/gpgkey | sudo apt-key add -

Key importation output:

2020-10-08 19:40:09 URL:https://d28dx6y1hfq314.cloudfront.net/505/623/gpg/dokku-dokku-FB2B6AA421CD193F.pub.gpg?t=1602179109_89e21c60fdf77e8ab2181ba23ae0dc910985dfbb [3937/3937] -> "-" [1]
OK

Add the repo using the commands below:

OS_ID="$(lsb_release -cs 2>/dev/null || echo "bionic")"
echo "deb https://packagecloud.io/dokku/dokku/ubuntu/ ${OS_ID} main" | sudo tee /etc/apt/sources.list.d/dokku.list

Then update system package list:

sudo apt update

Step 1: Install Docker Engine on Ubuntu 20.04|18.04

You can install either stable release of Docker or edge release, both are supported by Dokku.

wget -nv -O - https://get.docker.com/ | sudo bash -

Add your user account to docker group:

sudo usermod -aG docker $USER
newgrp docker

This is unattended installation, wait for it to complete then confirm docker engine version installed:

$ docker version
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:02:52 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:01:20 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Step 2: Install Dokku on Ubuntu 20.04|18.04

Once docker has been installed, you can proceed to install Dokku on your Ubuntu 20.04|18.04 LTS system. This is done by updating system packages and installing dokku package:

sudo apt update
sudo apt install dokku -y

Dependencies installed through apt include:

  • herokuish
  • sshcommand
  • plugn

When asked whether to enable web configuration interface, answer yes

Installation of dokku will also configure nginx for you and create a systemd service unit for managing the service. Installation output summary is shown below:

....
Adding user dokku to group adm
Starting nginx (via systemctl): nginx.service.
-----> Priming bash-completion cache
Ensure proper sshcommand path
Setting up dokku-installer
Enabling dokku-installer
Created symlink /etc/systemd/system/multi-user.target.wants/dokku-installer.service → /etc/systemd/system/dokku-installer.service.
Created symlink /etc/systemd/system/graphical.target.wants/dokku-installer.service → /etc/systemd/system/dokku-installer.service.
Starting dokku-installer
Processing triggers for libc-bin (2.31-0ubuntu9.1) ...
Processing triggers for ufw (0.36-6) ...
Processing triggers for systemd (245.4-4ubuntu3.2) ...
Processing triggers for man-db (2.9.1-1) ...

Install dokku dependencies:

sudo dokku plugin:install-dependencies --core

A user and group named dokku is also added to the system, its home directory is /home/dokku. This user account is used when deploying applications to Dokku.

$ id dokku
uid=1001(dokku) gid=1002(dokku) groups=1002(dokku),4(adm),998(docker)

$ ls -la /home/dokku/
total 44
drwxr-xr-x 5 dokku dokku 4096 Oct  8 19:45 .
drwxr-xr-x 4 root  root  4096 Oct  8 19:43 ..
drwxr-xr-x 2 dokku dokku 4096 Oct  8 19:45 .basher
-rw-r--r-- 1 dokku dokku  220 Oct  8 19:43 .bash_logout
-rw-r--r-- 1 dokku dokku 3771 Oct  8 19:43 .bashrc
-rw-r--r-- 1 dokku dokku    0 Oct  8 19:43 .cloud-locale-test.skip
drwxr-xr-x 2 dokku dokku 4096 Oct  8 19:43 .dokkurc
-rw-r--r-- 1 dokku dokku   29 Oct  8 19:43 HOSTNAME
-rw-r--r-- 1 dokku dokku  807 Oct  8 19:43 .profile
drwxr-xr-x 2 dokku dokku 4096 Oct  8 19:43 .ssh
-rw-r--r-- 1 dokku root    15 Oct  8 19:44 .sshcommand
-rw-r--r-- 1 dokku dokku   29 Oct  8 19:43 VHOST

The service should be running by default after the installation. The name of the service is dokku-installer.service:

$ systemctl status dokku-installer.service
● dokku-installer.service - Dokku web-installer
     Loaded: loaded (/etc/systemd/system/dokku-installer.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-10-08 19:44:41 CEST; 6min ago
   Main PID: 14789 (python3)
      Tasks: 1 (limit: 2286)
     Memory: 8.3M
     CGroup: /system.slice/dokku-installer.service
             └─14789 python3 /usr/share/dokku/contrib/dokku-installer.py selfdestruct

Oct 08 19:44:41 ubuntu systemd[1]: Started Dokku web-installer.
Oct 08 19:44:41 ubuntu sudo[14817]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/sbin/ufw status
Oct 08 19:44:41 ubuntu sudo[14817]: pam_unix(sudo:session): session opened for user root by (uid=0)
Oct 08 19:44:41 ubuntu sudo[14817]: pam_unix(sudo:session): session closed for user root

Confirm if the service is enabled to start on boot:

$ systemctl is-enabled dokku-installer.service
enabled

Dokku version can be checked using:

$ dokku version
dokku version 0.21.4

Step 3: Configure Dokku on Ubuntu 20.04|18.04

When done with the installation, go to your server’s IP and follow the web installer to configure Dokku.

Confirm:

  • SSH Public key that you’ll use to access Dokku apps.
  • Provide FQDN hostname for dokku to be used for apps URL
  • Check Use virtualhost naming to have your apps deployed on Dokku with hostnames

Then click “Finish Setup” button to finish Installation of Dokku on Ubuntu 20.04|18.04.

Note that Once you save your settings, the web admin will self-terminate and you should be able to run or deploy to the Dokku installation.

Upgrading Dokku on Ubuntu 20.04|18.04

To upgrade Dokku to the latest stable release, use dokku-update command:

sudo dokku ps:stopall
sudo apt update
sudo apt install -qq -y dokku herokuish sshcommand plugn gliderlabs-sigil
sudo sudo apt upgrade

Upgrading Dokku with above command will not affect the running dokku and automates many of the upgrade instructions for you. If you would like to rebuild all applications after the upgrade, use:

sudo dokku ps:rebuildall

Installing Dokku Plugins

Dokku provides a handful of Plugins to manage other functionalities. All are available on Dokku has official plugins. Installation of these plugins is done on the Dokku host as a root user or using a user account with sudo privileges.

See examples below:

Install PostgreSQL  datastore service:

sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git

Install MariaDB datastore plugin:

sudo dokku plugin:install https://github.com/dokku/dokku-mariadb.git mariadb

Deploying Apps to Dokku

Now that you have a working Dokku installation on your Ubuntu 20.04|18.04 system, you can begin deployment of applications. You can read a comprehensive guide on deploying apps to Dokku.

Conclusion

Dokku is a free and open-source Docker-based PaaS that allows you to basically do the same things as Heroku on your own infrastructure (on-premises or cloud). It is easy to setup and use. If you have any challenges with the installation and configuration, let me know through the comment section.

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF