Deploy Directus to Dokku

Roger Stringer

Roger Stringer / February 9, 2023

2 min read

Dokku is a handy PaaS service you can run on servers. I have it running on a couple Digital Ocean servers and it works nicely.

I also use Directus a lot as a Headless CMS and overall database management, so being able to quickly install is very handy.

Here's a little recipe I use to set it up. First, we want to create the app and set up everything we need:

dokku apps:create directus
dokku domains:add directus YOURDOMAIN
dokku postgres:create directus
dokku postgres:link directus directus

dokku storage:list directus
dokku storage:ensure-directory directus
dokku storage:mount directus /[SOME-FOLDER-ON-MACHINE]/data:/app/data
dokku ps:restart directus

dokku config:set --no-restart directus KEY=$(openssl rand -hex 32)
dokku config:set --no-restart directus SECRET=$(openssl rand -hex 32)
dokku config:set --no-restart directus ADMIN_EMAIL=[YOUR@EMAIL.com]
dokku config:set --no-restart directus ADMIN_PASSWORD=[YOUR-ADMIN-PASSWORD]
dokku config:set --no-restart directus PUBLIC_URL=[YOUR-DOMAIN]
dokku config:set --no-restart directus STORAGE_LOCATIONS="local"
dokku config:set --no-restart directus STORAGE_LOCAL_DRIVER="local"
dokku config:set --no-restart directus STORAGE_LOCAL_ROOT="/app/data/uploads"

dokku config:set --no-restart directus DB_CLIENT=pg
dokku config:set --no-restart directus DB_CONNECTION_STRING="<info from above command>"

dokku ports:set directus http:80:8055

This creates the app, and the database, and configures the app to use the env vars specified.

Next, we want to pull the Directus docker image and deploy it:

docker pull directus/directus
dokku git:from-image directus directus/directus

Last step is to set up our SSL certs:

dokku config:set --no-restart directus 
dokku letsencrypt:set directus email YOU@YOURDOMAIN
dokku letsencrypt:enable directus

That's it, you now have an Directus instance running, and you can add other instances quickly by making new apps.

To update, you can replace latest with any tag you want:

docker pull directus/directus:latest && dokku git:from-image directus directus/directus:latest

Do you like my content?

Sponsor Me On Github