Installing Dokku on Kubuntu

dokku, ubuntu, kubuntu, node


title: Installing Dokku on Kubuntu date: "2019-09-28" banner: ./images/featured-image.jpg published_at: "2019-09-29T02:55:42.000Z" tags: "dokku, ubuntu, kubuntu, node" author: Sung M. Kim

Image by StockSnap from Pixabay

As I was looking for ways to deploy a node & react site for intranet, I was looking for a self-hosted PaaS (Platform as a Service) I can deploy internally.

I was reading thru "Heroku vs self-hosted PaaS", I decided to go with Dokku (even though CapRover looked quite appealing as well) because I don't need to scale up to multiple servers for intranet pages.

I will show you how to install Dokku on Kubuntu (Ubuntu but with KDE Plasma Desktop Environment instead of Gnome) running on Windows Hyper-V.

My linux skill is lacking so will be using KDE to configure some Dokku features. You don't need Hyper-V to follow but can also use linux (even though Dokku recommends installing it on a VM) or use Linux VM such as KVM or Virtual Box, etc.

Be warned. I am just writing down these steps for me to come back so it might not be an optimal/recommended to follow these steps.

but please don't hesitate to let me know how to improve the flow (especially without using KDE).

Table of Contents

🚀 What we are building

This is basically what everything comes down to; Deploying a site to Dokku and open it outside VM.

Now you know how the result looks like, let's start with creating a VM (virtual machine).

🚀 Prerequisite

If you already has a VM with a linux on it, you can skip this part.

Download Kubuntu

Go to the Kubuntu download page and download "64-bit" version of " Kubuntu 18.04.3 LTS".

Emphasis on "64-bit" because

Dokku supports "A fresh installation of Ubuntu x64 - Any currently supported release, Debian 8.2 x64 or CentOS 7 x64 (experimental) with the FQDN set [1]" so you'd need 64-bit image.


Create a VM

You can create a VM manually or using a Wizard ("Quick Create") but as it's a prerequisite, let's create it using a Wizard. (At work, I will delegate this task to a ops manager as I am not so familiar with this frankly 😅).


This pops up a modal and select the Kubuntu ISO downloaded from the previous step. (If you are familiar with regular Ubuntu, you don't have to download Kubuntu at all...).

Make sure to turn off "This Virtual Machine will run Windows (enables secure boot)".

Lastly "Create Virtual Machine" and you are done.


By default the VM name is"New Virtual Machine". (I renamed it to "Kubuntu 18.04 LTS x64 for Dokku" by right clicking on it and choose "rename").

rename VM

You'd need to start the VM as it's off by default as well.

Connect and start VM

◼ Install Kubuntu

On connecting to VM, click on "start" to fire up a Kubuntu installation wizard (by default, the VM is in "Off" state as shown in the previous image).

Connect and start

Click on "Installation Kubuntu" to start the process.

Install Kubuntu

Set up the language, keyboard, timezone, etc and the user account (clicking next, next, next...).


It might take a while, so let's go and grab a cup of coffee ☕ and come back...

After installation has finished, restart Kubuntu (not the VM).

Restart Kubuntu

Lastly, log into Kubuntu and start a console.

We are all ready to set up Dokku, finally!

🚀 Install Dokku

Let's take a look at the Dokku installation instructions for apt. (It's a bit more involved than it looks).

# install docker
wget -nv -O - https://get.docker.com/ | sh
# setup dokku apt repository
-wget -nv -O - https://packagecloud.io/dokku/dokku/gpgkey | apt-key add -
+wget -nv -O - https://packagecloud.io/dokku/dokku/gpgkey | sudo apt-key add -
export SOURCE="https://packagecloud.io/dokku/dokku/ubuntu/"
export OS_ID="$(lsb_release -cs 2>/dev/null || echo "trusty")"
echo "utopicvividwilyxenialyakketyzestyartfulbionic" | grep -q "$OS_ID" || OS_ID="trusty"
-echo "deb $SOURCE $OS_ID main" | tee /etc/apt/sources.list.d/dokku.list
+echo "deb $SOURCE $OS_ID main" | sudo tee /etc/apt/sources.list.d/dokku.list
-apt-get update
+sudo apt-get update
# install dokku
-sudo apt-get install dokku
+sudo apt-get install dokku
-sudo dokku plugin:install-dependencies --core # run with root!
+sudo dokku plugin:install-dependencies --core # run with root!
# go to your server's IP and follow the web installer
# install docker
wget -nv -O - https://get.docker.com/ | sh
# setup dokku apt repository
wget -nv -O - https://packagecloud.io/dokku/dokku/gpgkey | sudo apt-key add -
export SOURCE="https://packagecloud.io/dokku/dokku/ubuntu/"
export OS_ID="$(lsb_release -cs 2>/dev/null || echo "trusty")"
echo "utopicvividwilyxenialyakketyzestyartfulbionic" | grep -q "$OS_ID" || OS_ID="trusty"
echo "deb $SOURCE $OS_ID main" | sudo tee /etc/apt/sources.list.d/dokku.list
sudo apt-get update
# install dokku
sudo apt-get install dokku
sudo dokku plugin:install-dependencies --core # run with root!
# go to your server's IP and follow the web installer

It's slightly different because the need to run some commands as a root using sudo.
The instruction is straight-forward (other than using sudo) I will leave out the output.

After you are done with the last instruction, sudo dokku plugin:install-dependencies --core, you will be greeted with a message whether to enable web-based configuration. Click "yes".

Enable web-based configuration

The last part of the instruction, # go to your server's IP and follow the web installer shows to open a web page to continue the installation.

You can get the current machine's name with hostname and open the web page on FireFox (installed even with Minimal Installation).

Fire up FireFox and go to https://<<your host name>.

In my case, hostname was set up as dokku, so https://dokku shows the following set up page.

Dokku Web Installation

I am not well-versed with Linux administration so I went and generated one by following Digital Ocean's article, "How to Set Up SSH Keys on Ubuntu 18.04 - Step 1 — Create the RSA Key Pair".

Open the public key (I used `Kate`, which is like "notepad" on Windows) by typing kate ~/.ssh/id_rsa.pub (".pub" for "public") and copy the public key.

Copy public SSH key from Kate

Paste the public key on the web configuration.

Paste SSH public key

Set the host name to the one returned by hostname command from Konsole.

Make sure to get the correct name with `hostname` or else , you'd have to manually change it later! (or access with an IP).

I will leave the "Use virtualhost naming for apps" turned off as turning it on would use port 80 and use app-name for the host name.

Check out the output when checked off. (leave this off though)

Use virtualhost name

When you click "Finish Setup", you will be directed to "Deploying to Dokku" page.

🚀 Deploy a Node app

"Deploying to Dokku" shows how to deploy a Ruby on Rails app but as I am not familiar with it at all, I will deploy a Node app (an Express server). And this also enables me not having to install postgres and other dependent services, making it simpler to demonstrate the deploy process.

Let's create ~/src folder (not to pollute the home directly, ~) and clone "node-js-getting-started" repository (repo, hereafter) from GitHub.

git clone https://github.com/heroku/node-js-getting-started.git

You might be wondering, "You are pasting code? You suck". Yes I know. But explaining how to create a Dokku deployable source with Procfile would be better left in another post as this post is titled "Installing Dokku on Kubuntu".

For now, you don't have to install packages as publishing to Dokku will take care of it automatically.

You need to create an application on where Dokku is hosted. (You can do so by SSH'ing to the host or just run it in Konsole within VM).

dokku apps:create node-js-getting-started

You will be asked to enter the root password.

Then a message will be shown that an app has been created successfully.

Dokku app created

Dokku is compatible with Heroku and works similiarly. That means the deployment can be done via git.

So let's add a remote git repo to deploy to.

# 1️⃣ 2️⃣ 3️⃣ 4️⃣
git remote add dokku dokku@dokku:node-js-getting-started
view raw add remote repo hosted with ❤ by GitHub

1️⃣ is the remote name
2️⃣ is the remote username
3️⃣ is the host name the Dokku instance is running on
4️⃣ is the app that you created in the previous step

When you try to deploy the Node app to Dokku by pushing it to remote dokku repo, you will get a "ssh: connect to host port 22: Connection refused" error.

We need to install SSH server & client as well as opening the port 22 (using ufw, "Uncomplicated Firewall"). Let's push it again while at it.

# Install Open SSH server & client
sudo apt install openssh-server openssh-client
# Open port 22 to allow connection
sudo ufw allow 22
# Deploy the code to Dokku
git push dokku master

When you push for the first time, you will be prompted by SSH client questioning the authenticity of the server. Just press "yes" to continue.

I am not familiar with this concept so had to google and found this reply (it's for bitbucket but the concept applies).

If you are attempting to push the second time, you will be prompted to enter the password you entered when generating the SSH key. The result of deploy looks like following.

dance2die@dokku:~/node-js-getting-started$ git push dokku master
Enter passphrase for key '/home/dance2die/.ssh/id_rsa':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 291 bytes | 291.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
-----> Cleaning up...
-----> Building node-js-getting-started from herokuish...
-----> Adding BUILD_ENV to build environment...
-----> Node.js app detected
-----> Creating runtime environment
-----> Installing binaries
engines.node (package.json): 10.x
engines.npm (package.json): unspecified (use default)
Resolving node version 10.x...
Downloading and installing node 10.16.3...
Using default npm version: 6.9.0
-----> Restoring cache
- node_modules
-----> Installing dependencies
Installing node modules (package.json)
added 79 packages from 65 contributors and audited 248 packages in 3.84s
found 0 vulnerabilities
-----> Build
-----> Pruning devDependencies
removed 79 packages and audited 127 packages in 1.386s
found 0 vulnerabilities
-----> Caching build
- node_modules
-----> Build succeeded!
-----> Discovering process types
Procfile declares types -> web
-----> Releasing node-js-getting-started (dokku/node-js-getting-started:latest)...
-----> Deploying node-js-getting-started (dokku/node-js-getting-started:latest)...
-----> App Procfile file found (/home/dokku/node-js-getting-started/DOKKU_PROCFILE)
DOKKU_SCALE declares scale -> web=1
-----> Attempting pre-flight checks
For more efficient zero downtime deployments, create a file CHECKS.
See http://dokku.viewdocs.io/dokku/deployment/zero-downtime-deploys/ for examples
CHECKS file not found in container: Running simple container check...
-----> Waiting for 10 seconds ...
-----> Default container check successful!
-----> Running post-deploy
-----> VHOST support disabled. Skipping domains setup
-----> Creating http nginx.conf
-----> Running nginx-pre-reload
Reloading nginx
-----> Renaming containers
Found previous container(s) (5e9e0a95731a) named node-js-getting-started.web.1
Renaming container (5e9e0a95731a) node-js-getting-started.web.1 to node-js-getting-started.web.1.1569718919
Renaming container (bccaa0d7a197) goofy_rhodes to node-js-getting-started.web.1
-----> Shutting down old containers in 60 seconds
=====> Application deployed:
97e6c72..1d859f3 master -> master

🚀 Check the deployed app

At the bottom of the deployment log, you will see the deployment URL.

Deploy URL

I am not sure how to expose VM hostname outside, so browser inside VM uses https://dokku:PORT to access while outside VM, it is using the IP.

Please let me know if you know of a way to access the VM hostname outside the VM... 🙏

👋 Parting Words

As mentioned in the opening, I wrote this as more of a self-note and is a learning process (for Dokku, VM, Linux, etc.).

There should be many steps that I am doing, either unnecessary, or plain out wrong.

Please let me know how I can improve the process or leave comment on what is just dead right wrong.

🏔 Resources

Below are resources mentioned in this post.