Dokku (Self-hosted Heroku)

Dokku

Dokku is an extensible, open source Platform as a Service that runs on a single server of your choice. Dokku supports building apps on the fly from a git push via either Dockerfile or by auto-detecting the language with Buildpacks, and then starts containers based on your built image. Using technologies such as nginx and cron, Web processes are automatically routed to, while background processes and automated cron tasks are also managed by Dokku.

Homepage: https://dokku.com/, Quickstart

I've been using this for a while to host all my sites under https://kevbot.xyz without issue. I started using it because of this Youtube tutorial series

How I Use Dokku to Host my Webapps

Here's the steps I take.

  1. Buy a domain name from namecheap. It should be $10/year or less. Buying firstnamelastname.xyz or .com is usually a good idea.
  2. I buy a VPS from low end box for about $40/year. I ensure my VPS is in a nearby region for low ping when I'm SSH'd in. I try to get one with ~3GB of ram and as much disk as possible (like over 50GB). This is a bit overkill but it's nice to have more space on the box.
  3. For the operating system on the VPS, I choose the latest Ubuntu LTS.
  4. I SSH into the new box, and I install Dokku.
  5. It's ready for git push type ops now.

Fun fact, this page you're reading right now is hosted on Dokku.

Dokku Alternatives

Another good option would be coolify.io it's got a more UI-based option, though I've never used it (I hear good things). How do Coolify and Dokku compare?

On the other hand, if you really like docker, I can recommend https://caprover.com/ over dokku. It's a similar concept to dokku, but it exposes more of the Dockery docker-doos to you, the developer. 

Pros of Dokku

  • Allows for very easy self-hosting. As a matter of fact I believe you have to self-host it. I don't think Dokku-as-a-service exists (well, there's Heroku but that's not so commonly recommended nowadays.)
  • Dokku is very actively maintained (mostly by Jose Gonzalez). With great documentation.
  • Rich plugin ecosystem. 
  • GitOps. Dokku servers function as git servers, so you just push a new repo and it builds a new publicly-exposed app in ~1 min.
    • example: git remote add dokku dokku@DOKKU_HOST:myapp && git push dokku.  You'll soon have a deployed app under https://myapp.kevbot.xyz. To update it, just push again.
    • This encourages, if not enforces, 12 Factor style app design which is good.
  • CLI-based everything. You can deploy / manage stuff from local machine, or you can ssh onto the actual server and  manage things there. 
  • Can run many Apps on the box. Currently I have 20 apps plus 6 Databases running on one machine (which has 4GB of ram).
  • Can run many DBs on the box (see here for a full list). On my single box, I'm currently currently running 3 Redis, 2 Postgres, and 1 mariadb instances.
  • Dokku has a great build system that you usually don't have to wrestle with much once you understand it. I'm usually using the herokuish buildpacks for Python, Node, or static site buildpacks. And sometimes Dockerfile-based deployments. You have many options, including nix-based deployments though I've never tried that. Just search dokku on github for a bunch of projects people have made.

Meh

  • You have to run either Ubuntu or Debian on your Dokku server. And depending on how many apps you want to run, I'd recommend at least 2gb ram and at least 20gb disk. (My racknerd VPS has 3 cpu cores, 4gb ram, 80gb ssd). 
  • Dokku supports autoscaling, but I've never used it for that. I think Dokku is most straightforward used single-node, but who knows?

Cons

  • No official web dashboard. This does exist in the Dokku Pro version (which I do not yet have). You can get by using ctop, for a tui dashboard, though (see below).
  • Sometimes upgrading dokku versions can be a bit of a pain. There is sudo dokku-update run --system-update which helps out some. See docs
  • You kind of have to start with a freshly installed VPS and it kind of “takes over” a lot of your system's networking details. I've never tried adding Dokku to a VPS that I've been using for a while.
  • Once you get away from the happy-path of using-buildpacks-someone-else-has-already-made, things can get tricky. Dockerfile deployments exist, but can get hairy. Docker Compose deployments do not exist at all (as of Jan 2024 at least).
  • Definitely not serverless-style architecture. Your Dokku instance will be a pet-server. You can set up full-system backups which can be restored quite easily.
  • Dokku uses a lot of bespoke concepts, tooling, build systems, and more. You'll sometimes need to add files in your repo like app.json, .buildpacks, .static, or apt-packages. You aren't all that locked into Dokku from this, though as these files are pretty light in content generally.

A nice command to view container resource usage and more

# run this on the actual dokku machine
sudo docker run --rm -ti \
                      --name=ctop \
                      --volume /var/run/docker.sock:/var/run/docker.sock:ro \
                      quay.io/vektorlab/ctop:latest

More docs on ctop here: https://github.com/bcicen/ctop

If you need to free up space

Docker tends to kind of fill the hard drive up with cruft such as old containers / layers and stuf.

This command will clear all your unused and cached containers. Your next builds will likely take longer, due to the cache removal.

sudo docker system prune -a