Dokku on DigitalOcean with Debian

First thing have to worried about when it comes to self-host a bunch of micro-services is how you going to manage all these kinds of containers?

I came across Dokku, a docker powered mini-Heroku solution, best thing is you don't have to mess around all kinds of Docker commands and let Dokku manage most of the things for you, which includes database, letsencrypt, and domain management.

First thing I did is boot up a fresh droplet, since AMD is on trends nowadays I choose 2C4G Premium AMD droplet, also, if you can do all the things on Debian, why choose pre-built image on Digital Ocean with "slightly" outdated Dokku?

After droplet is ready, you need to install ufw, because Digital Ocean is not like AWS EC2 have prebuilt firewall rules, it's better for you set it up manually, ufw is also easy to set it up and solid for everyday usage. After that you should set ufw like this below for everything we need later.

UFW settings

Install Dokku

Trust me, it's SUPER EASY, everyone with basic copy-paste knowledge can install it, just follow the step.

 # for debian systems, installs dokku via apt-get

  wget https://raw.githubusercontent.com/dokku/dokku/v0.26.6/bootstrap.sh

  sudo DOKKU_TAG=v0.26.6 bash bootstrap.sh

 # Configure your server domain via `dokku domains:set-global`

 # and user access (via `dokku ssh-keys:add`) to complete the installation

Copy and paste two lines starts without # and bang! Dokku is ready for use.

Setting up Dokku and Global Domain to use

Here comes a little difficult part, set the SSH access. You may wondering why we have to do this, it's because some of the Docker image we going to build is require full git repository files in the same folder to build the image, for generate the configuration file, use the assets inside the folder and such.

Another great thing with Dokku is you can push the repository to Dokku, and let it "automatically" do the build and deploy the application.

# usually your key is already available under the current user's `~/.ssh/authorized_keys` file
cat ~/.ssh/authorized_keys | dokku ssh-keys:add admin

# you can use any domain you already have access to
dokku domains:set-global dokku.me
Add SSH and global domain

After you ran the commands above, you should have Dokku set with SSH keys you use to access to droplet, and a domain Dokku will use for every apps. By default after you set global domain Dokku will use <app_name>.domain.tld for every apps, this can also be change before and after you deploy the image.

Install Dokku plugins

We've setup our SSH keys and global domain, now we can install the plugins we need to use.

The essential plugins we are going to install is PostgresSQL / Redis / Letsencrypt.

PostgresSQL is required almost every modern application, Redis is widely use for cache and letsencrypt is for SSL certificate registrations.

# dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
# dokku plugin:install https://github.com/dokku/dokku-redis.git redis
# dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
Installation commands for plugins

And now your droplet is ready for deploy all kinds of applications!