# Self-host Hasura

> An instant GraphQL and REST API on top of Postgres with permissions, subscriptions and an admin console.

- Page: https://levelrail.com/templates/hasura/
- JSON: https://levelrail.com/templates/hasura.json
- Category: Developer Tools
- Licence: Apache-2.0 (Permissive license)
- Source: https://github.com/hasura/graphql-engine
- Upstream docs: https://hasura.io/docs/2.0/deployment/docker/

## Requirements
- Memory: about 512 MiB
- amd64: published, arm64: published
- Needs configuration before start: no
- Pinned image tag: 16-alpine

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| db | postgres | 16-alpine | none | pgdata -> /var/lib/postgresql/data |
| hasura | hasura/graphql-engine | v2.51.0 | 8080 | none |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| db | POSTGRES_DB | preset |
| db | POSTGRES_PASSWORD | generated |
| db | POSTGRES_USER | preset |
| hasura | HASURA_GRAPHQL_ADMIN_SECRET | generated |
| hasura | HASURA_GRAPHQL_DEV_MODE | preset |
| hasura | HASURA_GRAPHQL_ENABLED_LOG_TYPES | preset |
| hasura | HASURA_GRAPHQL_ENABLE_CONSOLE | preset |
| hasura | HASURA_GRAPHQL_METADATA_DATABASE_URL | generated |
| hasura | PG_DATABASE_URL | generated |

## Deploy

### CLI

```bash
levelrail-cli templates install hasura --name my-hasura
```

Add --domain SERVICE=HOST to serve a service on your own domain, for example --domain db=app.example.com.

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  https://levelrail.example.com/api/v1/service-templates/hasura/install \
  -d '{
    "name": "my-hasura"
  }'
```

Create a token in the dashboard first. Name, env and domains are the request fields.

## Questions

### Can I deploy Hasura on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for Hasura, so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image postgres:16-alpine, hasura/graphql-engine:v2.51.0 is what you deploy there.

Self-host Hasura, Hasura docker compose file, deploy Hasura on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
