Deploy PostgREST to Dokku

Create a new app

dokku apps:create pgrest-myproject

Add a port mapping from 3000 (PostgREST container) to 80 (host).

dokku ports:add pgrest-myproject http:80:3000

Create a new PostgreSQL database using the dokku-postgres plugin and link it to our project.

dokku postgres:create pgrest-myproject
dokku posgres:link pgrest-myproject pgrest-myproject

A new environment variable will be created:

=====> pgrest-myproject
DATABASE_URL: postgres://postgres:alongpass@dokku-postgres-pgrest-myproject:5432/pgrest_myproject

But we need to define the same value in a variable named PGRST_DB_URI so PostgREST can access the database.

dokku config:set pgrest-myproject PGRST_DB_URI="postgres://postgres:alongpass@dokku-postgres-pgrest-myproject:5432/pgrest_myproject"

Pull and deploy the Docker image from dockerhub.

docker pull postgrest/postgrest:latest
docker tag postgrest/postgrest:latest dokku/postgrest:latest
dokku git:from-image pgrest-myproject dokku/postgrest:latest

Add a Let’s Encrypt TLS certificate with the Dokku letsencrypt plugin.

dokku letsencrypt:set pgrest-myproject email <your-email>
dokku letsencrypt:enable pgrest-myproject

Leave a Reply

Your email address will not be published. Required fields are marked *