How to Create & Setup Dokku Applications & Databases
As I have mentioned many of times before, Dokku rocks! Dokku is a free and open-source project that helps you build and manage the lifecycle of your applications. Dokku does is it by leveraging the power of Docker and Heroku Buildpacks.
It's perfect for solo developers or small teams that want to run their own PaaS (Platform as a Service) and save both time and money in the process. I use Dokku myself and found lots of joy in doing so. It helps me focus more on my projects, and less on the server and deployment process.
In the previous tutorial I showed you how you can install Dokku on a DigitalOcean droplet. Today I will follow along in those footsteps and show you how you can setup your applications, install a database and link it to your application.
SSH into your Dokku instance.
ssh root@123.456.789.101
Create application with Dokku's apps:create command.
Once you have authenticated with your server we can go ahead and create our apps with the apps:create dokku command.
dokku apps:create backend
dokku apps:create frontend
Dokku provieds an apps:list command which we can use to verify that all apps was created correctly.
dokku apps:list
If our apps where created sucessfully they should be displayed in the list.
=====> My Apps
backend
frontend
Setup a Database
In this example we will install and setup a PostgreSQL database with our project. To be able to use PostgreSQL we need to install a dokku plugin. We do it so that we can run the database separate from our app container, as that container will be rebuilt when your push a new version of your application.
Dokku provides a bunch software available as plugins, including MySQL, PostgreSQL, MongoDB, Redis, Let's Encrypt (for SSL certificates) and many more. Here you can find the list of the available plugins.
Dokku itself is actually built out of the very same plugin system. Since Dokku is just a collection of scripts that run apps using the official Heroku Buildpacks, which are open-sourced as well.
Install the Dokku Postgres Plugin
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
Create a PostgreSQL database
dokku postgres:create databasename
We can use the postgres:info command to get the nessesary information to configure the database with our application.
dokku postgres:info databasename
Finially we need to link our database with our app container, in this case "backed".
dokku postgres:link databasename backend
In the next tutorial we will take a closer look at how we can use Git and GitLab's pipelines for CI/CD (Continuous Integration/Continuous Deployment). So that we can safely push our code to our Git repository and then onto the server and rebuild the application.