The Hidden Blog

As it turns out, I do have a hostname.

Selfhosting with Dokku and Docker Compose

Published on Aug 28, 2024

A few days ago I was happy to see a post about Dokku on the HN frontpage. This reminded me that I wanted to briefly write up my experience of switching to Dokku as well.

I've recently set up a new server and was looking into a nice way to organize my various websites and an easy to way self-host my Rails apps without having to spend a lot of money on expensive cloud services. I do neither need the possibility to "scale" nor is downtime a big issue.

My main constraints were:

  • Easy deploys for Rails apps

  • Easy deploys for PHP apps (Kirby, running this blog you are reading right now)

  • Works nicely with other Docker containers on the server that are not managed by whatever software I end up using

  • Web interface, not a high priority

There's a few candidates that cover some of these constraints, some are paid:

As already mentioned at the beginning I've decided to use Dokku. It's very simple, easy to uninstall without any interruptions to the running services and it officially supports mixed workloads. This allows me to run Docker containers managed by Dokku and others that are managed through a regular Docker Compose file side by side. I have more complicated services that I didn't want to port to Dokku right away (or ever) so this was a big selling point to me.

Getting clarification on this was also the first interaction I had with the project as I've asked that question in their GitHub community. I've received a response from the maintainer within 2 hours!

It's in essence a very polished Shell script that makes managing apps running on my server a bit nicer than before where I had to manually edit nginx configs, pull containers, edit my large docker-compose file and create data directors to be used as volumes. It does all of that with a few—well documented—commands.

Example

As a short example, here's what's needed to have a static site, hosted on a domain with a Let's Encrypt certificate live.

  1. Point your domain to the server

  2. Run touch .static in your website's repository, this just tells Dokku that it's a static site and no Heroku Buildpack has to be used (It would identify if it's a Rails app, PHP app or other frameworks and perform the necessary build steps automatically)

  3. SSH into the server and create the app (See commands below)

  4. Add your Dokku git remote to the repository and git push

  5. The website is now live.

The "apps" in Dokku are created with a few simple commands. In that case that would be:

dokku apps:create dewey.at
dokku domains:set dewey.at dewey.at www.dewey.at
dokku letsencrypt:enable dewey.at

The documentation is great and if you are stuck there's always Github, Discord and IRC.

If you are looking for a simple way of deploying your services without paying a lot, give it a try! If you end up using it, consider sponsoring it.