Installing Dokku on Kubuntu
dokku, ubuntu, kubuntu, node
dokku, ubuntu, kubuntu, node
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.
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).
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).
If you already has a VM with a linux on it, you can skip this part.
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 " so you'd need 64-bit image.
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").
You'd need to start the VM as it's off by default as well.
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).
Click on "Installation Kubuntu" to start the process.
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).
Lastly, log into Kubuntu and start a console.
We are all ready to set up Dokku, finally!
Let's take a look at the Dokku installation instructions for apt. (It's a bit more involved than it looks).
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".
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.
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.
Paste the public key on the web configuration.
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)
When you click "Finish Setup", you will be directed to "Deploying to Dokku" page.
"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 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️⃣ 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 192.168.22.242 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.
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.
At the bottom of the deployment log, you will see the deployment 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... 🙏
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.
Below are resources mentioned in this post.