How to Install Supabase with Docker on Ubuntu 24.04

This article details the installation of Supabase on Ubuntu 24.04 using Docker. Supabase offers an open-source alternative to Firebase, leveraging PostgreSQL for data management. The process involves installing Docker, downloading Supabase, configuring necessary settings, and implementing security measures like SSL/TLS for a dependable development environment.

This article explains how to install Supabase with Docker on Ubuntu 24.04.

Supabase, a Firebase alternative, is an open-source backend-as-a-service platform that empowers developers to build their apps. With its PostgreSQL database, real-time capabilities, authentication, and instant APIs, Supabase simplifies the backend setup and management.

Having Supabase installed locally allows developers to build and test applications in a controlled environment without relying on external services.

Since Supabase relies on PostgreSQL, installing it on Ubuntu allows you to leverage the powerful features of this relational database system, including complex queries, relationships, and data integrity.

Install Docker Engine

To deploy Supabase on your server, you must install Docker Engine. This allows Supabase applications to run within a container on your server.

Before installing Docker, run the command below to install some prerequisite packages.

sudo apt update
sudo apt install ca-certificates curl git

Once the packages are installed, continue to install Docker below.

First, add the GPG key for the Docker Engine repository by running the command below.

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

Next, add the Docker repository to Ubuntu by running the command below.

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Once the Docker GPG key and repository have been added to Ubuntu, run the command below to install the Docker app.

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

After installing Docker, you should run it with a non-root user account. It is recommended that a dedicated user for Supabase be created to run the app. Then, add the user to the Docker group.

Add your user to the ‘docker‘ group with the command below.

sudo usermod -aG docker $USER

Log out and restart your machine so your account can be fully added to the Docker group.

Install Supabase

Now that Docker is installed and configured, download Supabase using the command below.

git clone --depth 1 https://github.com/supabase/supabase

Next, create Supabase environment config file from the example file.

cd supabase/docker/
cp .env.example .env

Then, run the command below to download Supabase images from the Docker repository.

docker compose pull

Once the process is done, execute the command below to start Supabase containers.

docker compose up -d

Docker should be started but not properly configured. The steps below walk you through configuring Supabase.

Configure Supabase

Although Supabase is up and running on your system, password and authentication are not set up yet.

To do that, generate passwords for the PostgreSQL server, and Supabase dashboard, and then generate the JWT secret and token.

The command below can be used to generate secrets.

openssl rand -hex 16

The command should output secrets that you can use later in Supabase config file.

After that, go to the Supabase website to generate two JWT tokens for Supabase. Run this form twice to generate new anon and service API keys.

Once all the tokens and secrets are generated, open Supabase environment configuration file.

nano .env

Configure the highlighted lines with the appropriate settings.

Updat the ‘POSTGRES_PASSWORD‘ using the OpenSSL password generated. Update the ‘JWT_SECRET‘ with the one generated from Supabase website. Do the same for the ‘ANON_KEY‘ and the ‘SERVICE_ROLE_KEY‘ values.

###########
# Secrets
# YOU MUST CHANGE THESE BEFORE GOING INTO PRODUCTION
############

POSTGRES_PASSWORD=b26d8c7220e2abac6c2cb090ce9bf4a3
JWT_SECRET=3135pJUeF863MLQ8WaadlYmMW49gb5Hax8t9zEFQ
ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJyb2xlIjo............
SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJ............
DASHBOARD_USERNAME=supabase
DASHBOARD_PASSWORD=75672d66af67b1565b1540f2d2ae6309

Update the URL section to enter your correct URLs.

## General
SITE_URL=http://localhost:3000
ADDITIONAL_REDIRECT_URLS=
JWT_EXPIRY=3600
DISABLE_SIGNUP=false
API_EXTERNAL_URL=http://localhost:8000

Save the file and exit the editor when finished.

Next, stop and relaunch Supabase docker container for the changes to apply.

docker compose down
docker compose up -d

You can sign in to the dashboard using the URL below:

http://localhost:8000

Type in the supabase account and password in the config file (.env).

Set up a reverse proxy

Now that Supabase is set up, you can use a reverse proxy to ensure the app is accessible via a domain name and optimize for web traffic.

The two links below show you how to set up a reverse proxy using Nginx or Apache.

Setup Let’s Encrypt SSL/TLS

You may want to install an SSL/TLS certificate to secure your Supabase site. Secure the app installation with HTTPS from Let’s Encrypt.

Please read the post below for additional resources on installing and creating Let’s Encrypt SSL certificates for Apache.

That should do it!

Conclusion:

In summary, installing Supabase on Ubuntu using Docker provides developers with a robust backend solution that simplifies app development and testing. Here are the key takeaways:

  • Open-source Alternative: Supabase serves as a powerful open-source substitute for Firebase, offering similar functionalities.
  • Ease of Setup: Utilizing Docker streamlines the installation process and allows for easy management of the Supabase environment.
  • PostgreSQL Integration: Leveraging PostgreSQL enhances data management capabilities, ensuring data integrity and complex querying.
  • Local Development: Running Supabase locally enables safe testing and development, minimizing dependency on external services.
  • Security Measures: Setting up password and authentication, as well as implementing SSL/TLS with Let’s Encrypt, ensures a secure environment.
  • Scalability and Flexibility: The architecture allows for easy scaling as projects grow, adapting to increasing demands.

By following the steps outlined, developers can confidently harness the potential of Supabase to build and deploy applications efficiently.

Richard Avatar

Comments

Leave a Reply

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


Exit mobile version