When I have free time, I like to create different side-projects or test my ideas. Since 2016 I’m using DigitalOcean as a cheap solution to host my projects. I created an instance per project and paid 5$/month for each of instances. It was until I found Dokku. You can run multiple applications with a configured deployment under one instance. Yep, you can test your mini-startups, small projects only for 5$ per month for all projects. In this post, I will show you how to run multiple Node.js apps under one instance.
To follow this tutorial you should have the basic fundamentals of the command line, SSH and must be registered on DigitalOcean. If you have no account, you can sign up using my referral link and receive 100$ of credit for 60 days. This money will be enough to host your apps for 2 months and play with all possible features.
What is the Dokku?
Dokku is a platform as a service. It’s like a Heroku, but it can be your own. On your own server. You can deploy, manage and scale your own applications to your own cloud.
Setup DigitalOcean Droplet
Open DigitalOcean platform on “Droplets” Page, press ” Create” and select “Droplets”:
Select Ubuntu v14.04.5 x64 and the cheapest server:
Choose a suitable region for your cloud hosting, additional options and SSH keys that will be used for connecting:
In the last step you need to give a name for your droplet and press “Create” button:
Now you have created your first droplet. You will be redirected to “Droplets” page and can see the process of installation. After successful installation, you will get the IP address of your hosting:
Open your SSH client (in my case I’m used the Mac OS terminal) and connect to your hosting:
ssh root@<your droplet ip>
If the connection was ok, run the command that installs Dokku:
and press the “Enter” button. The installation process will begin and will take about 5 minutes:
Run command dokku to make sure the installation was ok:
Now, we should finish setup. Go to instance-IP address in web-browser. You should see the following page:
Press “Finish Setup” and wait for some seconds before the server will be configured.
Setup Swap file
In the next sections, we will create 2 Node.js apps. They will require some quantity of memory. Due to the memory of our droplet (1 GB), we can increase it by creating the swap file. We will store some memory in this file when RAM will run out of memory.
Go to your cloud terminal and run:
Then give permission to file:
Set up swap:
The terminal should output the following text: “Setting up swapspace version 1, size = 8388604 KiB no label, UUID=bc0b60a4-ece9-4813-ba1d-267ac7159bbf”.
You can enable swap file using the following:
That’s all. You can top command and see the available memory:
In this section, we will create two Dokku apps and run them on different ports under one IP.
Let’s create two Dokku apps on our hosting using the following:
dokku apps:create app1&&dokku apps:create app2
Then, go to your local machine and create two Node.js projects. As an example, we will take Node.js example from Heroku. We can install them using the following: