taksa1990/nostr-relay

By taksa1990

Updated 6 months ago

A production-ready Nostr relay server.

Image
Networking
Web servers
0

638

taksa1990/nostr-relay repository overview

Build & Publish Docker Pulls Image Size

Nostr Relay Server – Full Deployment Guide with Docker Compose

This guide covers running a production-ready Nostr Relay Server with Postgres and Redis, using Docker Compose. It also covers optional NIP-96 file storage, environment configurations, and monitoring.


1. Prerequisites

Before starting, ensure you have:

  • Docker installed (docker --version)
  • Docker Compose installed (docker compose version)
  • A server or local machine with at least 2 GB RAM (more recommended for production)
  • Optional: Domain name and SSL setup (for HTTPS)

2. Directory Structure

Create a project directory, e.g., nostr-relay, with the following structure:

nostr-relay/
├─ docker-compose.yml
├─ .env                 # optional file to store environment variables
└─ data/
   └─ postgres/         # PostgreSQL persistent storage

3. Environment Variables

You can set variables in the docker-compose.yml directly, or store them in a .env file:

# .env
NODE_ENV=production
PORT=8080
DATABASE_URL=postgres://user:password@postgres:5432/nostr
REDIS_URL=redis://redis:6379
RELAY_NAME=My Nostr Relay
RELAY_DESCRIPTION=Secure Nostr relay server
REQUIRE_AUTH_FOR_WRITE=false
RUN_MIGRATIONS=1
MAX_MESSAGE_SIZE=1048576
STORAGE_METHOD=local         # optional, for NIP-96
BASE_URL=http://your-domain.com/files
MAX_FILE_SIZE=104857600      # optional 100 MB max file size

4. Docker Compose File

Here’s a full docker-compose.yml for production:

version: "3.9"

services:
  nostr-relay:
    image: taksa1990/nostr-relay:latest
    container_name: nostr-relay
    environment:
      NODE_ENV: ${NODE_ENV}
      PORT: ${PORT}
      DATABASE_URL: ${DATABASE_URL}
      REDIS_URL: ${REDIS_URL}
      RELAY_NAME: ${RELAY_NAME}
      RELAY_DESCRIPTION: ${RELAY_DESCRIPTION}
      REQUIRE_AUTH_FOR_WRITE: ${REQUIRE_AUTH_FOR_WRITE}
      RUN_MIGRATIONS: ${RUN_MIGRATIONS}
      MAX_MESSAGE_SIZE: ${MAX_MESSAGE_SIZE}
      STORAGE_METHOD: ${STORAGE_METHOD}
      BASE_URL: ${BASE_URL}
      MAX_FILE_SIZE: ${MAX_FILE_SIZE}
    ports:
      - "8080:8080"
    depends_on:
      - postgres
      - redis
    restart: unless-stopped
    networks:
      - nostr-net
    volumes:
      - nostr-files:/app/files   # for NIP-96 local file storage

  postgres:
    image: postgres:13
    container_name: nostr-postgres
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: nostr
    volumes:
      - nostr-postgres-data:/var/lib/postgresql/data
    networks:
      - nostr-net
    restart: unless-stopped

  redis:
    image: redis:6
    container_name: nostr-redis
    networks:
      - nostr-net
    restart: unless-stopped

volumes:
  nostr-postgres-data:
  nostr-files:

networks:
  nostr-net:

5. Running the Relay

  1. Pull images and start containers:
docker compose pull
docker compose up -d
  1. Check logs to ensure everything started properly:
docker compose logs -f nostr-relay
  1. Access endpoints:
  • Health check: http://HOST:8080/health
  • Readiness: http://HOST:8080/ready
  • NIP-11 info: http://HOST:8080/.well-known/nostr.json
  • Metrics: http://HOST:8080/metrics

6. Optional: NIP-96 File Storage

  • Local storage: Files saved in nostr-files volume.
  • S3 storage: Set STORAGE_METHOD=s3 and add S3 credentials:
S3_BUCKET=your-bucket-name
S3_REGION=your-region
AWS_ACCESS_KEY_ID=your-key
AWS_SECRET_ACCESS_KEY=your-secret
  • Files are accessible via ${BASE_URL}/filename.

7. Database Migration

  • Ensure RUN_MIGRATIONS=1 on the first run to initialize the database.
  • Later, you can set RUN_MIGRATIONS=0 to prevent accidental schema changes.

8. Monitoring

  • Use Prometheus and Grafana to monitor metrics at /metrics.
  • Example Prometheus scrape config:
scrape_configs:
  - job_name: nostr-relay
    static_configs:
      - targets: ['YOUR_HOST:8080']

9. Backups

  • Postgres: Use volume snapshots or pg_dump:
docker exec nostr-postgres pg_dump -U user nostr > nostr_backup.sql
  • Files: Backup nostr-files volume.

10. Troubleshooting

  • Relay not starting: Check logs, confirm Postgres and Redis URLs are correct.
  • Port conflicts: Make sure 8080 is free.
  • File storage errors: Verify permissions for nostr-files volume.
  • High memory usage: Reduce MAX_MESSAGE_SIZE or limit events stored.

Tag summary

Content type

Image

Digest

sha256:11a72bb2e

Size

68.8 MB

Last updated

6 months ago

Requires Docker Desktop 4.37.1 or later.