Docker Compose Deployment
Deploy Nexgent's infrastructure services (PostgreSQL and Redis) using Docker Compose, then run the application natively.
This guide is ideal for local development and simple production setups on a single server.
Prerequisites
- Docker Desktop installed and running (download (opens in a new tab))
- Node.js 18.0.0 or higher (download (opens in a new tab))
- pnpm 8.0.0 or higher (install (opens in a new tab))
- Git for cloning the repository
Quick Start
Clone the Repository
git clone https://github.com/Nexgent-ai/nexgent-open-source-trading-engine.git
cd nexgentStart Infrastructure Services
docker-compose up -dThis starts:
- PostgreSQL on port
5432 - Redis on port
6379
Verify services are running:
docker-compose psYou should see both nexgent-postgres and nexgent-redis with status "Up".
Install Dependencies
pnpm installConfigure Environment Variables
cd packages/backend
cp env.example .envEdit .env with minimum required values:
# Database (matches Docker Compose defaults)
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/nexgent?schema=public"
# Redis (matches Docker Compose defaults)
REDIS_HOST=localhost
REDIS_PORT=6379
# Server
PORT=4000
NODE_ENV=development
CORS_ORIGIN=http://localhost:3000
# JWT Secret (generate with: pnpm generate-secret:backend)
JWT_SECRET="your-generated-secret-here"Generate Secrets
# From project root
pnpm generate-secret # Frontend (NextAuth)
pnpm generate-secret:backend # Backend (JWT)Copy the generated secrets into your .env files.
Run Database Migrations
pnpm --filter backend db:migrateThis creates all necessary database tables.
Start the Application
# Start both frontend and backend
pnpm dev
# Or start separately
pnpm dev:backend # Backend on http://localhost:4000
pnpm dev:frontend # Frontend on http://localhost:3000Verify Installation
- Frontend: http://localhost:3000 (opens in a new tab)
- Backend health: http://localhost:4000/api/v1/health (opens in a new tab)
- Prisma Studio:
pnpm --filter backend db:studio→ http://localhost:5555 (opens in a new tab)
Docker Compose Configuration
The included docker-compose.yml:
services:
postgres:
image: postgres:14-alpine
container_name: nexgent-postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: nexgent
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
redis:
image: redis:7-alpine
container_name: nexgent-redis
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
volumes:
postgres_data:Production Deployment
For production on a single server, use the same Docker Compose setup with additional configuration.
1. Update Environment Variables
Backend .env:
# Database
DATABASE_URL="postgresql://postgres:STRONG_PASSWORD@localhost:5432/nexgent?schema=public"
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# Server
PORT=4000
NODE_ENV=production
CORS_ORIGIN=https://your-domain.com
# Security
JWT_SECRET="your-production-jwt-secret"
# External APIs
JUPITER_API_KEY=your-jupiter-api-key
SOLANA_RPC_URL=https://your-rpc-endpointFrontend .env.local:
NEXTAUTH_URL=https://your-domain.com
NEXTAUTH_SECRET="your-production-nextauth-secret"
NEXT_PUBLIC_API_URL=https://api.your-domain.com2. Secure Docker Compose
Create docker-compose.prod.yml:
services:
postgres:
image: postgres:14-alpine
container_name: nexgent-postgres
environment:
POSTGRES_USER: nexgent
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: nexgent
ports:
- "127.0.0.1:5432:5432" # Only localhost
volumes:
- postgres_data:/var/lib/postgresql/data
restart: always
redis:
image: redis:7-alpine
container_name: nexgent-redis
command: redis-server --requirepass ${REDIS_PASSWORD}
ports:
- "127.0.0.1:6379:6379" # Only localhost
restart: always
volumes:
postgres_data:Run with environment variables:
POSTGRES_PASSWORD=your-strong-password \
REDIS_PASSWORD=your-redis-password \
docker-compose -f docker-compose.prod.yml up -d3. Build for Production
# Build all packages
pnpm build
# Start production servers
pnpm start4. Use a Process Manager
Install PM2 for process management:
npm install -g pm2Create ecosystem.config.js:
module.exports = {
apps: [
{
name: 'nexgent-backend',
cwd: './packages/backend',
script: 'dist/index.js',
instances: 1,
env: {
NODE_ENV: 'production',
},
},
{
name: 'nexgent-frontend',
cwd: './packages/frontend',
script: 'node_modules/.bin/next',
args: 'start',
instances: 1,
env: {
NODE_ENV: 'production',
},
},
],
};Start with PM2:
pm2 start ecosystem.config.js
pm2 save
pm2 startup # Auto-start on boot5. Set Up Reverse Proxy
Use Nginx as a reverse proxy. See Production Checklist for SSL configuration.
Managing Services
Start Services
docker-compose up -dStop Services
# Stop (keeps data)
docker-compose stop
# Stop and remove containers (keeps data)
docker-compose down
# Stop and remove everything (DELETES ALL DATA)
docker-compose down -vView Logs
# All services
docker-compose logs -f
# Specific service
docker-compose logs -f postgres
docker-compose logs -f redisCheck Health
docker-compose psBoth services should show "healthy" status.
Database Management
Access PostgreSQL
# Via Docker exec
docker exec -it nexgent-postgres psql -U postgres -d nexgent
# Via psql (if installed locally)
psql -h localhost -U postgres -d nexgentPrisma Studio
cd packages/backend
pnpm db:studioOpens a visual database browser at http://localhost:5555 (opens in a new tab).
Run Migrations
# Development
pnpm --filter backend db:migrate
# Production (apply only, no prompts)
pnpm --filter backend db:migrate:deployReset Database
# Stop everything and delete data
docker-compose down -v
# Start fresh
docker-compose up -d
pnpm --filter backend db:migrateTroubleshooting
Port Already in Use
Check what's using the port:
netstat -ano | findstr :5432
taskkill /PID <pid> /FOr change ports in docker-compose.yml:
ports:
- "5433:5432" # Map to different host portContainer Won't Start
# Check logs
docker-compose logs postgres
# Remove and recreate
docker-compose down
docker-compose up -dCan't Connect to Database
- Verify container is running:
docker-compose ps - Check health status shows "healthy"
- Verify
.envcredentials matchdocker-compose.yml - Ensure Docker Desktop is running
Permission Denied (Linux)
sudo usermod -aG docker $USER
# Log out and back in