Emailyze can be self-hosted using Docker Compose. This deployment runs the full stack—web app, Celery workers, Celery Beat, PostgreSQL, and Redis—on your own infrastructure. All data stays on your servers, making it suitable for enterprises with compliance or data sovereignty requirements. This guide covers prerequisites, configuration, deployment, initial data setup, and production hardening.

Overview: Full Stack, Data on Your Servers

The Docker Compose setup runs five services: web (Django/Gunicorn), celery (async task worker), celery-beat (scheduled tasks), db (PostgreSQL 15), and redis (cache and broker). The web service serves the API and dashboard; Celery handles background jobs (ETL, exports, bulk checks); Celery Beat runs the ETL pipeline on a schedule (fetch every 15 minutes, merge every 6 hours, enrich/score/publish hourly). All application data is stored in PostgreSQL; Redis is used for caching and as the Celery message broker.

Prerequisites

You need Docker and Docker Compose installed. On Ubuntu/Debian: apt install docker.io docker-compose-plugin. On macOS: Docker Desktop. Ensure Docker has enough resources: at least 2GB RAM and 2 CPU cores for a small deployment; scale up for production. The stack uses healthchecks so services wait for dependencies (e.g., web waits for db and redis to be healthy).

Configuration

Clone the repository and copy the environment template: cp .env.example .env. Edit .env and set at minimum: SECRET_KEY (a random string for Django; generate with openssl rand -hex 32), ALLOWED_HOSTS (comma-separated list of hostnames, e.g., emailguard.example.com,localhost), and optionally DEBUG (set to False in production). The Compose file wires DATABASE_URL and REDIS_URL automatically; override in .env if using external services.

Deploy

From the project root, run: docker compose up -d --build. This builds the web and Celery images, starts all services, and runs them in the background. The web app listens on port 8000. Check logs with docker compose logs -f web or docker compose logs -f celery. To stop: docker compose down.

Initial Data

The database starts empty. You need to ingest domain data. Options: (1) Run the ingest_domains management command inside the web container: docker compose exec web python manage.py ingest_domains. (2) Use a Celery task if you've configured a data source. (3) Restore from a backup. Until domains are loaded, the check API will return mostly unknown/empty results. The ETL pipeline will populate data over time if configured.

Create Admin and API Key

Create a superuser: docker compose exec web python manage.py createsuperuser. Follow the prompts. Create an API key for programmatic access: docker compose exec web python manage.py create_apikey --user [email protected]. Save the key securely; it's shown only once. Use it in the X-API-Key header or ?key= query parameter for API requests.

Production: Reverse Proxy and TLS

For production, put a reverse proxy (nginx or Caddy) in front of the web service. Configure TLS with Let's Encrypt or your certificate provider. Example nginx config: proxy https://emailguard.example.com to http://localhost:8000. Set ALLOWED_HOSTS to include your domain. Consider increasing Gunicorn workers and Celery concurrency for higher load.

ETL Schedule

The Celery Beat schedule runs: fetch (every 15 min), merge (every 6 hours), enrich/score/publish (hourly). These tasks update the domain database and generate the JSONL snapshot for the download endpoint. Adjust in emailguard/celery.py if needed.

Service Details

The web service runs Gunicorn with 2 workers by default; increase for production. The celery worker processes async tasks (bulk checks, CSV uploads, ETL). The celery-beat service runs the scheduler; only one instance should run to avoid duplicate task execution. db uses PostgreSQL 15 with a persistent volume; backup regularly. redis is used for Celery broker and Django cache; ensure it has enough memory for your workload.

Volumes and Persistence

The pgdata volume persists PostgreSQL data across container restarts. Without it, data would be lost on docker compose down. For Redis, data is typically ephemeral (cache); if you need Redis persistence, add a volume in the Compose file. Application code is baked into the image at build time; mount a volume only if you need to override config files.

Logs and Debugging

View logs with docker compose logs -f [service]. For web: docker compose logs -f web. For Celery: docker compose logs -f celery. Set DEBUG=True in .env for development (never in production). Run management commands with docker compose exec web python manage.py . To shell into the container: docker compose exec web bash.

Updating

Pull the latest code, rebuild, and restart: git pull && docker compose build --no-cache && docker compose up -d. Run migrations if needed: docker compose exec web python manage.py migrate. Backup the database before major updates.

Environment Variables Reference

Key variables in .env: SECRET_KEY (required), ALLOWED_HOSTS (required in production), DEBUG (False in production), DATABASE_URL (defaults to postgresql://postgres:postgres@db:5432/emailguard), REDIS_URL (defaults to redis://redis:6379/0). Optional: SITE_URL for absolute URLs in emails, EMAIL_ for SMTP, CELERY_ for task configuration. The Compose file injects DATABASE_URL and REDIS_URL from the linked db and redis services.

Health Checks

PostgreSQL and Redis have healthchecks; the web and Celery services depend on them with condition: service_healthy. This ensures the app doesn't start before the database is ready. For custom health endpoints, the web app may expose /health/ or similar; configure your load balancer to use it. If a service fails to become healthy, Docker will retry; check logs for connection errors or misconfiguration.

Scaling

For higher throughput, scale the Celery worker: docker compose up -d --scale celery=3. Ensure Redis and PostgreSQL can handle the load. Use a connection pooler (e.g., PgBouncer) if you scale web workers significantly. The web service can be scaled behind a load balancer; ensure sessions or stickiness are configured if needed. Celery Beat must remain a single instance; do not scale it.

Backup and Restore

Backup PostgreSQL regularly: docker compose exec db pg_dump -U postgres emailguard > backup.sql. Restore with docker compose exec -T db psql -U postgres emailguard < backup.sql. Schedule backups with cron or your preferred tool. Test restores periodically.

See Also