Install Dokku
Deploy the site with git push instead of file transfer, with the cost written out and the database moved out before it disappears.
Last reviewed:
What Dokku is
A way to deploy a website by sending the code with git. You write git push dokku main, and a few seconds later the new version is running on the server. Dokku works out for itself which language the code is written in, installs what is needed and restarts the service.
No file transfer, no manual restart, no list of steps that someone forgets at eleven at night. Deployment becomes one command, and if it becomes one command you dare to do it often.
This is the shortest path in the whole collection from code on your computer to a real web address. Compare with Argo CD, which does something similar but requires Kubernetes and a completely different time budget.
This requires a server, and it costs money
Dokku is installed on a server, not on your own computer. The point is that the site should be reachable around the clock, and that calls for a machine that sits with someone else.
The requirements are an Ubuntu or Debian server with at least 1 GB of memory. One of those costs from about fifty SEK a month. That is a real expense that belongs in the company budget before you start, and it continues every month.
A domain name is not necessary to get started, but it soon will be. Count on a few hundred SEK a year there as well.
Installation
You log in to the server with SSH. You do this from PowerShell on Windows and from Terminal on Linux Mint, with the same command: ssh root@serverns-adress. This assumes that your public SSH key is already with the server provider, and most ask for it when you order the server. Then run on the server:
wget -NP . https://dokku.com/install/v0.38.27/bootstrap.sh
sudo DOKKU_TAG=v0.38.27 bash bootstrap.sh
The version number in the command was the current one when the guide was written. Check what is current at dokku.com and replace both places if it has changed. The installation takes five to ten minutes.
Then two lines that give you access to the system from outside:
cat ~/.ssh/authorized_keys | sudo dokku ssh-keys:add admin
dokku domains:set-global er-doman.se
With this, each app gets the address appnamn.er-doman.se, and that requires a wildcard record, meaning a DNS record for *.er-doman.se that points to the server's IP address. Without it, nobody can reach the apps. HTTPS does not come automatically either, but requires its own plugin: sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git, then dokku letsencrypt:set --global email er-mejladress and dokku letsencrypt:enable butik for each app.
Three things to do first
- Install git on your own computer if it is not already there, because without it there is nothing to push with. On Windows:
winget install Git.Gitin PowerShell, then close the window and open a new one. On Linux Mint:sudo apt-get install git. - Create the app on the server with
dokku apps:create butik, then add the server as a target in your repo at home:git remote add dokku dokku@serverns-adress:butik. Now the connection exists, and it is what makes the rest possible. - Make your first deployment with
git push dokku mainand read what scrolls past in the window. You will see Dokku recognize the language, fetch dependencies and start. If something goes wrong it is right there, and that is the only troubleshooting you need at the start.
The most common trap
Believing that the files the app creates stay in place. Every deployment builds a new container from your code, and the old one is thrown away. Everything the app has saved to disk, meaning uploaded images and a database file that sits in the project folder, disappears on the next push. You do not notice the first time, because nothing had been saved yet. You notice in November.
So put the database outside the app. The Postgres plugin is not part of the basic installation, so install it first with sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git. After that, dokku postgres:create butik-db followed by dokku postgres:link butik-db butik is enough for most projects. Uploaded files go in a persistent folder outside the app, with two lines on the server:
dokku storage:ensure-directory butik
dokku storage:mount butik /var/lib/dokku/data/storage/butik:/app/uppladdningar
The first line creates the folder, the second mounts it into the app. The path after the colon is the one the app writes to.
Do this before you have real customers, not after. Moving data afterwards is possible, but it is an evening you would rather spend on something else.