Skip to content

Docker Deployment

Docker Compose is the fastest way to deploy OpenSNS. It handles PostgreSQL, the backend API, and the frontend in a single command.

Terminal window
git clone https://github.com/opensns-dev/opensns.git
cd opensns

Copy the example environment file and generate required secrets:

Terminal window
cp .env.example .env
# Generate required security keys
openssl rand -hex 32 # Use output for JWT_SECRET_KEY
openssl rand -hex 32 # Use output for API_KEY_ENCRYPTION_KEY

Edit .env with your generated keys:

Terminal window
# REQUIRED
JWT_SECRET_KEY=<your-generated-key>
API_KEY_ENCRYPTION_KEY=<your-generated-key>
# OPTIONAL - AI service API keys (users can also set in Settings UI)
OPENAI_API_KEY=sk-...
FAL_KEY=...
Terminal window
docker compose up -d

This starts:

ServicePortDescription
PostgreSQLInternal onlyDatabase (not exposed externally)
Backend8000FastAPI server
Frontend3000Next.js app
Terminal window
# Check all containers are running and healthy
docker compose ps
# Check backend health
curl http://localhost:8000/health
# Open frontend
open http://localhost:3000

Internet
┌──────────────┴──────────────┐
│ │
┌─────▼─────┐ ┌─────▼─────┐
│ Frontend │ │ Backend │
│ :3000 │ │ :8000 │
└───────────┘ └─────┬─────┘
│ │
│ frontend-net │
└─────────────────────────────┘
backend-net
┌───────▼───────┐
│ PostgreSQL │
│ (internal) │
└───────────────┘

Network Security:

  • PostgreSQL is NOT exposed to the internet (internal network only)
  • Frontend and Backend are on separate networks
  • Backend bridges both networks to access the database

VariableDescriptionHow to Generate
JWT_SECRET_KEYJWT signing key (min 32 chars)openssl rand -hex 32
API_KEY_ENCRYPTION_KEYAES key for API key encryptionopenssl rand -hex 32
VariableDescription
OPENAI_API_KEYOpenAI API key for LLM
FAL_KEYFal.ai API key for images/video
VariableDescription
HEYGEN_API_KEYHeyGen API key for AI avatar videos
DID_API_KEYD-ID API key for AI avatar videos
SADTALKER_URLSelf-hosted SadTalker endpoint
VariableOptionsDefault
DEFAULT_LLM_ENGINEopenai, ollama, mockopenai
DEFAULT_IMAGE_ENGINEfal, flux-pro, comfyuifal
DEFAULT_VIDEO_ENGINEfal-video, runway, comfyui-videofal-video
DEFAULT_UGC_ENGINEheygen, d-id, sadtalkerheygen
VariableDescription
OLLAMA_URLOllama API endpoint for local LLM
COMFYUI_URLComfyUI WebSocket URL
VariableDefaultDescription
FRONTEND_URLhttp://localhost:3000Frontend URL for email links
CORS_ORIGINShttp://localhost:3000Allowed CORS origins (comma-separated)
NEXT_PUBLIC_API_URLhttp://localhost:8000Backend API URL for frontend
NEXT_PUBLIC_WS_URLws://localhost:8000WebSocket URL for frontend
VariableDescription
PADDLE_API_KEYPaddle API key
PADDLE_WEBHOOK_SECRETPaddle webhook secret
PADDLE_ENVIRONMENTsandbox or production
VariableDescription
RESEND_API_KEYResend API key for emails
EMAIL_FROMSender email address
GOOGLE_CLIENT_IDGoogle OAuth client ID
GOOGLE_CLIENT_SECRETGoogle OAuth client secret

Terminal window
# All services
docker compose logs -f
# Specific service
docker compose logs -f backend
docker compose logs -f frontend
Terminal window
# Restart all
docker compose restart
# Restart specific service
docker compose restart backend
Terminal window
# Stop but keep data
docker compose down
# Stop and remove volumes (DELETES DATA)
docker compose down -v
Terminal window
# Rebuild and restart
docker compose build
docker compose up -d
# Or with version tag
VERSION=1.0.0 docker compose build
VERSION=1.0.0 docker compose up -d
Terminal window
# Access PostgreSQL shell
docker compose exec postgres psql -U opensns -d opensns
# Backup database
docker compose exec postgres pg_dump -U opensns opensns > backup.sql
# Restore database
cat backup.sql | docker compose exec -T postgres psql -U opensns -d opensns

For production with HTTPS, update these variables:

Terminal window
FRONTEND_URL=https://app.yourdomain.com
CORS_ORIGINS=https://app.yourdomain.com
NEXT_PUBLIC_API_URL=https://api.yourdomain.com
NEXT_PUBLIC_WS_URL=wss://api.yourdomain.com

Important: NEXT_PUBLIC_* variables are baked into the frontend at build time. You must rebuild the frontend image when changing these:

Terminal window
docker compose build frontend
docker compose up -d

The default configuration includes sensible resource limits:

ServiceMemory LimitMemory Reserved
PostgreSQL512MB256MB
Backend2GB512MB
Frontend512MB256MB

Adjust in docker-compose.yml under deploy.resources.

Remove the postgres service and update DATABASE_URL:

backend:
environment:
DATABASE_URL: postgresql://user:pass@your-db-host:5432/opensns

Terminal window
# Check logs
docker compose logs backend
# Common issues:
# - Missing required env vars: Check JWT_SECRET_KEY and API_KEY_ENCRYPTION_KEY
# - Port already in use: Change port in docker-compose.yml
Terminal window
# Check if backend is starting
docker compose logs backend
# Verify database connection
docker compose exec backend python -c "from app.db import engine; print('DB OK')"

For Docker deployments, the frontend connects to backend via the host machine:

Terminal window
# Verify backend is accessible
curl http://localhost:8000/health

If using custom domain, ensure NEXT_PUBLIC_API_URL was set correctly at build time.

Increase Docker’s memory limit in Docker Desktop settings, or adjust container limits in docker-compose.yml.


Generate ad creatives from any product URL. Open source, self-hostable, free tier available.

Try OpenSNS Free →