A ready-to-use template for deploying a self-hosted Convex backend using Docker Compose and Traefik for reverse proxying and SSL termination.
This setup allows you to easily run an isolated Convex instance, perfect for development, staging, or production environments. It includes:
- Convex Backend: The core Convex runtime.
- Convex Dashboard: The web UI for managing your Convex deployment.
- PostgreSQL: The required database backend for Convex.
- Traefik Integration: Pre-configured labels for automatic HTTPS routing based on domain names.
- Easy Configuration: Simple
.env
file for setting instance name, domain, ports, and credentials. - Multi-Instance Ready: Deploy multiple isolated Convex backends by changing the
APP_NAME
in the.env
file. - Traefik v3 Ready: Uses modern Traefik Docker labels for automatic service discovery and routing.
- Persistent Storage: Data for PostgreSQL and Convex is stored in named Docker volumes.
- (Optional) Direct Port Exposure: Uncomment
ports
incompose.yml
for direct access if needed.
- Docker
- Docker Compose
- A server with a publicly accessible IP (for HTTPS with Let's Encrypt via Traefik).
- A Traefik instance configured to watch the
traefik-default
Docker network.- Your Traefik must be configured with an entrypoint for
websecure
(e.g.,:443
) and a Let's EncryptcertResolver
namedletsencrypt
. - The network
traefik-default
must exist. Create it withdocker network create traefik-default
if it doesn't.
- Your Traefik must be configured with an entrypoint for
- (Optional, for direct access) Ensure the ports defined in your
.env
(e.g.,POSTGRES_EXTERNAL_PORT
) are open on your server's firewall.
-
Clone the Repository:
git clone https://github.com/Alexandrsv/convex-selfhosted-traefik-template.git my-app cd my-app
-
Configure your Instance:
- Copy the example environment file:
cp .env.example .env
- Edit the
.env
file:nano .env
- Crucial: Change at least the
APP_NAME
andDOMAIN
. - Update
POSTGRES_USER
andPOSTGRES_PASSWORD
with secure credentials.
- Copy the example environment file:
-
Ensure Traefik Network Exists: Make sure the Docker network
traefik-default
exists:docker network ls | grep traefik-default
If it's missing, create it:
docker network create traefik-default
-
Start the Services:
docker compose up -d
-
Access your Services (via Traefik):
- Convex Dashboard:
https://dashboard.<your-domain-from-env>
- Convex API:
https://api.<your-domain-from-env>
- Convex Site/HTTP Actions:
https://<your-domain-from-env>
- Convex Dashboard:
-
Generate Admin Token (for Dashboard Login): Run the provided script to generate an admin token for the Convex Dashboard:
./generate_admin_key.sh
This script will execute the token generation inside the backend container and display the token in a friendly format.
To stop and remove the containers and volumes:
# warning: this will delete all stored data including your database!
docker compose down -v