How To setup Listmonk with Dokku

Listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a PostgreSQL (⩾ 12) database as its data store.

Dokku is an open source PAAS alternative to Heroku. Dokku helps you build and manage the lifecycle of applications from building to scaling.

Deploying listmonk on dokku took a little extra effort so here is a simple tutorial in case I forget next time.

This tutorial assumes you have dokku installed and are semi-familiar with deploying and running applications on dokku.

  1. Create Dokku app

dokku apps:create listmonk

  1. Create postgres database

dokku postgres:create listmonk-db

  1. Link the postgres database

dokku postgres:link listmonk-db listmonk

  1. Set Environment Variables for config

If the Database_URL is:

postgres://postgres:99c22ef4fa9b4eeeec730ea463533356@dokku-postgres-listmonk-db:5432/listmonk_db

Set each environment variable (Change the listmonk admin user and password!):

dokku config:set listmonk LISTMONK_app__address="0.0.0.0:9000"
dokku config:set listmonk LISTMONK_app__admin_username="listmonk"
dokku config:set listmonk LISTMONK_app__admin_password="listmonk"
dokku config:set listmonk LISTMONK_db__host="dokku-postgres-listmonk-db"
dokku config:set listmonk LISTMONK_db__port="5432"
dokku config:set listmonk LISTMONK_db__user="postgres"
dokku config:set listmonk LISTMONK_db__password="99c22ef4fa9b4eeeec730ea463533356"
dokku config:set listmonk LISTMONK_db__database="listmonk_db"
dokku config:set listmonk LISTMONK_db__ssl_mode="disable"
  1. Run a temp container to setup the initial db

dokku git:sync --build listmonk https://github.com/pastorhudson/dokku-listmonk-db-setup.git main

Enter the container:

dokku run listmonk

Create a config.toml file: Edit the db information

cat <<EOF > config.toml
[app]
address = "0.0.0.0:9000"
admin_username = "listmonk"
admin_password = "password"

# Database.
[db]
host = "dokku-postgres-listmonk-db"
port = 5432
user = "postgres"
password = "99c22ef4fa9b4eeeec730ea463533356"
database = "listmonk_db"
ssl_mode = "disable"
max_open = 25
max_idle = 25
max_lifetime = "300s"
EOF

Download the listmonk executable:

wget https://github.com/knadh/listmonk/releases/download/v3.0.0/listmonk_3.0.0_freebsd_amd64.tar.gz

Extract the executable:

tar -xvf listmonk_3.0.0_freebsd_amd64.tar.gz

Run the db install:

./listmonk --install

If it worked you should be able to press y and it will setup the db.

  1. Exit the temp container

exit

  1. Setup domain: Changet this to your own

dokku domains:add listmonk somedomain.mydomain.com

dokku letsencrypt:set listmonk email <e-mail>

dokku letsencrypt:enable listmonk

  1. Setup Ports

dokku ports:set https:443:9000

  1. Pull the correct container

dokku git:from-image listmonk listmonk/listmonk:latest

If all went well then you should have listmonk running on your dokku server at the url you configured.