Docker Compose Setup
This guide covers deploying VaultSandbox using Docker Compose, from basic development setups to production-ready configurations.
Quick Start
Section titled “Quick Start”Choose your setup method:
| Method | Variables | DNS Setup | Best For |
|---|---|---|---|
| VSX DNS | 1 | Automatic | Quick testing, CI/CD, getting started |
| Custom Domain | 2 | Manual | Production, compliance, branding |
Option 1: VSX DNS (Simplest)
Section titled “Option 1: VSX DNS (Simplest)”Zero-config setup with automatic domain assignment. Just 1 environment variable:
services: gateway: image: vaultsandbox/gateway:latest ports: - '25:25' - '80:80' - '443:443' environment: VSB_VSX_DNS_ENABLED: 'true' volumes: - gateway-data:/app/data
volumes: gateway-data:docker compose up -dYour domain is automatically assigned (e.g., 1mzhr2y.vsx.email). Find it at vsx.email or run:
docker compose exec gateway cat /app/data/certificates/metadata.json; echoOption 2: Custom Domain
Section titled “Option 2: Custom Domain”Use your own domain with just 2 environment variables:
services: gateway: image: vaultsandbox/gateway:latest ports: - '25:25' - '80:80' - '443:443' environment: VSB_SMTP_ALLOWED_RECIPIENT_DOMAINS: 'qa.example.com' VSB_CERT_ENABLED: 'true' volumes: - gateway-data:/app/data
volumes: gateway-data:Requires DNS setup: Create A and MX records pointing to your server. See Custom Domain Quick Start for details.
VaultSandbox runs as a single unified gateway service that includes the SMTP server, API, and web UI all in one container.
Configuration Reference
Section titled “Configuration Reference”VSX DNS Mode
Section titled “VSX DNS Mode”| Variable | Description |
|---|---|
VSB_VSX_DNS_ENABLED | Set to true to enable automatic DNS via vsx.email |
Custom Domain Mode
Section titled “Custom Domain Mode”| Variable | Description | Example |
|---|---|---|
VSB_SMTP_ALLOWED_RECIPIENT_DOMAINS | Domains to accept emails for (comma-separated) | qa.example.com,test.example.com |
VSB_CERT_ENABLED | Enable automatic Let’s Encrypt TLS certificates | true |
Optional Configuration
Section titled “Optional Configuration”Override defaults for advanced use cases:
| Variable | Default | Description |
|---|---|---|
VSB_LOCAL_INBOX_MAX_TTL | 604800 | Max email retention in seconds (7 days) |
VSB_LOCAL_INBOX_DEFAULT_TTL | 3600 | Default inbox TTL in seconds (1 hour) |
VSB_LOCAL_CLEANUP_INTERVAL | 300 | Cleanup interval for expired inboxes (5 min) |
VSB_SMTP_PORT | 25 | SMTP port (must be 25 for real email) |
VSB_SERVER_PORT | 80 | HTTP port for ACME challenges |
VSB_SERVER_HTTPS_PORT | 443 | HTTPS port for Web UI and API |
VSB_SERVER_ORIGIN | (auto) | CORS origins (auto-derived from domain, or use *) |
VSB_DATA_PATH | /app/data | Path for certificates and API keys |
NODE_ENV | production | Node environment |
Basic Deployment
Section titled “Basic Deployment”Step 1: Create Configuration
Section titled “Step 1: Create Configuration”mkdir vaultsandbox && cd vaultsandboxCreate docker-compose.yml. Choose your mode:
VSX DNS (recommended for getting started):
services: gateway: image: vaultsandbox/gateway:latest container_name: vaultsandbox-gateway restart: unless-stopped
ports: - '25:25' # SMTP - '80:80' # HTTP (ACME + VSX verification) - '443:443' # HTTPS (Web UI + API)
environment: VSB_VSX_DNS_ENABLED: 'true'
volumes: - gateway-data:/app/data
healthcheck: test: ['CMD', 'curl', '-f', 'http://localhost/health'] interval: 30s timeout: 10s retries: 3 start_period: 40s
volumes: gateway-data:Custom Domain:
services: gateway: image: vaultsandbox/gateway:latest container_name: vaultsandbox-gateway restart: unless-stopped
ports: - '25:25' # SMTP - '80:80' # HTTP (ACME challenges) - '443:443' # HTTPS (Web UI + API)
environment: VSB_SMTP_ALLOWED_RECIPIENT_DOMAINS: 'qa.example.com' VSB_CERT_ENABLED: 'true'
volumes: - gateway-data:/app/data
healthcheck: test: ['CMD', 'curl', '-f', 'http://localhost/health'] interval: 30s timeout: 10s retries: 3 start_period: 40s
volumes: gateway-data:Step 2: Start the Gateway
Section titled “Step 2: Start the Gateway”docker-compose up -dStep 3: Verify Service
Section titled “Step 3: Verify Service”# Check service statusdocker compose ps
# View logsdocker compose logs -f gateway
# Check health endpointcurl http://localhost/health
# Get your API keydocker compose exec gateway cat /app/data/.api-key; echoStep 4: Access Web UI
Section titled “Step 4: Access Web UI”Navigate to https://qa.example.com/app (or your domain).
Production Deployment
Section titled “Production Deployment”Production deployments typically use Custom Domain mode for branding and compliance.
Step 1: Create Production Configuration
Section titled “Step 1: Create Production Configuration”mkdir vaultsandbox && cd vaultsandboxCreate docker-compose.yml with production settings:
services: gateway: image: vaultsandbox/gateway:latest container_name: vaultsandbox-gateway restart: unless-stopped
ports: - '25:25' # SMTP - '80:80' # HTTP (ACME challenges) - '443:443' # HTTPS (Web UI + API)
environment: # Core configuration VSB_SMTP_ALLOWED_RECIPIENT_DOMAINS: 'qa.example.com,staging.example.com' VSB_CERT_ENABLED: 'true'
# Optional production settings VSB_LOCAL_INBOX_MAX_TTL: '604800' # 7 days VSB_SERVER_ORIGIN: 'https://qa.example.com' # Restrict CORS
volumes: - gateway-data:/app/data # Persist certificates and API keys
healthcheck: test: ['CMD', 'curl', '-f', 'http://localhost/health'] interval: 30s timeout: 10s retries: 3 start_period: 40s
# Resource limits (adjust based on your needs) deploy: resources: limits: cpus: '2' memory: 4G reservations: cpus: '1' memory: 2G
# Logging configuration logging: driver: 'json-file' options: max-size: '10m' max-file: '3'
volumes: gateway-data:Step 2: Start the Gateway
Section titled “Step 2: Start the Gateway”docker-compose up -dStep 3: Monitor Logs
Section titled “Step 3: Monitor Logs”# Follow logsdocker compose logs -f gateway
# Check for errorsdocker compose logs gateway | grep ERROR
# Verify certificate provisioningdocker compose logs gateway | grep -i certificateAdvanced Configuration
Section titled “Advanced Configuration”Health Checks
Section titled “Health Checks”VaultSandbox includes built-in health checks:
healthcheck: test: ['CMD', 'curl', '-f', 'http://localhost/health'] interval: 30s timeout: 10s retries: 3 start_period: 40sCustomize health check behavior:
healthcheck: interval: 60s # Check every 60 seconds timeout: 5s # Timeout after 5 seconds retries: 5 # Retry 5 times before marking unhealthy start_period: 60s # Wait 60s before starting checksLogging Configuration
Section titled “Logging Configuration”Control log output:
logging: driver: 'json-file' options: max-size: '10m' # Max 10MB per log file max-file: '3' # Keep 3 log filesOr use syslog:
logging: driver: 'syslog' options: syslog-address: 'tcp://192.168.0.42:514'Managing Services
Section titled “Managing Services”Start Services
Section titled “Start Services”docker compose up -dStop Services
Section titled “Stop Services”docker compose stopRestart Service
Section titled “Restart Service”docker compose restart
# Or restart gateway specificallydocker compose restart gatewayView Logs
Section titled “View Logs”# Follow logsdocker compose logs -f gateway
# Last 100 linesdocker compose logs --tail=100 gateway
# Filter for specific eventsdocker compose logs gateway | grep -i "certificate\|api key\|error"Update Images
Section titled “Update Images”# Pull latest imagesdocker compose pull
# Restart with new imagesdocker compose up -dRemove Services
Section titled “Remove Services”# Stop and remove containersdocker compose down
# Remove containers and volumes (WARNING: deletes all data)docker compose down -vTroubleshooting
Section titled “Troubleshooting”Service Won’t Start
Section titled “Service Won’t Start”Check logs:
docker compose logs gatewayCommon issues:
- Port 25 already in use (another mail server running)
- Ports 80/443 already in use
- Invalid domain configuration in
VSB_SMTP_ALLOWED_RECIPIENT_DOMAINS
Cannot Access Web UI
Section titled “Cannot Access Web UI”Check if gateway is running:
docker compose ps gatewayTest from server:
curl http://localhost/healthcurl http://localhost/appCheck DNS:
dig A qa.example.comAccess web UI at correct path: Remember the UI is at /app, not root:
https://qa.example.com/appCertificate Errors
Section titled “Certificate Errors”Check certificate logs:
docker compose logs gateway | grep -i certificateCommon issues:
- Ports 80/443 not accessible from internet
- DNS not pointing to server
- Domain validation timeout
Disable certificates for local testing:
environment: VSB_CERT_ENABLED: 'false'Emails Not Received
Section titled “Emails Not Received”Check SMTP logs:
docker compose logs gateway | grep -i smtpTest SMTP connection:
telnet qa.example.com 25Verify MX records:
dig MX qa.example.comUse the DNS Setup Tool: Visit vaultsandbox.com/setup to verify your DNS configuration.
High Memory Usage
Section titled “High Memory Usage”Check current usage:
docker stats vaultsandbox-gatewayReduce resource limits:
deploy: resources: limits: memory: 2G # Reduce from 4GReduce email retention:
environment: VSB_LOCAL_INBOX_MAX_TTL: '86400' # 24 hours instead of 7 daysContainer Keeps Restarting
Section titled “Container Keeps Restarting”Check logs:
docker compose logs gateway --tail=50Check health status:
docker inspect vaultsandbox-gateway | grep Health -A 10Disable health checks temporarily:
healthcheck: disable: trueCan’t Find API Key
Section titled “Can’t Find API Key”Check API key from container:
docker compose exec gateway cat /app/data/.api-key; echoCheck logs:
docker compose logs gateway | grep -i "api key"If file doesn’t exist: Remove the volume and restart to regenerate:
docker compose downdocker volume rm vaultsandbox_gateway-data # Or your volume namedocker compose up -dPerformance Tuning
Section titled “Performance Tuning”Resource Allocation
Section titled “Resource Allocation”For different workload sizes:
Light (< 1000 inboxes):
deploy: resources: limits: cpus: '1' memory: 2GMedium (1000-5000 inboxes):
deploy: resources: limits: cpus: '2' memory: 4GHeavy (5000+ inboxes):
deploy: resources: limits: cpus: '4' memory: 8GEmail Retention Configuration
Section titled “Email Retention Configuration”Shorter TTL = less memory usage:
environment: # 1 hour (good for CI/CD pipelines) VSB_LOCAL_INBOX_MAX_TTL: "3600"
# 24 hours (good for manual testing) VSB_LOCAL_INBOX_MAX_TTL: "86400"
# 7 days (default, good for staging) VSB_LOCAL_INBOX_MAX_TTL: "604800"Security Hardening
Section titled “Security Hardening”API Key Management
Section titled “API Key Management”VaultSandbox automatically generates a secure API key on first startup. The key is persisted to a Docker volume at /app/data/.api-key.
Retrieve your API key:
# From Docker containerdocker compose exec gateway cat /app/data/.api-key; echo
# Or using Docker CLIdocker exec vaultsandbox-gateway cat /app/data/.api-key; echoRotate API key:
# Delete the key file from inside the containerdocker compose exec gateway rm /app/data/.api-key
# Restart the gateway to generate a new keydocker compose restart gateway
# Retrieve the new keydocker compose exec gateway cat /app/data/.api-key; echoFor production deployments:
- Explicitly set
VSB_LOCAL_API_KEYin your environment to use a custom key - Use
VSB_LOCAL_API_KEY_STRICT=trueto require manual configuration
Restrict CORS Origins
Section titled “Restrict CORS Origins”For production, restrict CORS to specific origins:
environment: VSB_SERVER_ORIGIN: 'https://qa.example.com,https://app.example.com'Use Firewall Rules
Section titled “Use Firewall Rules”Only expose necessary ports:
# Allow required portssudo ufw allow 25/tcp # SMTPsudo ufw allow 80/tcp # HTTP (ACME)sudo ufw allow 443/tcp # HTTPSsudo ufw enable
# Deny all other incoming trafficsudo ufw default deny incomingNext Steps
Section titled “Next Steps”- Deployment Setup - DNS and TLS configuration
- Node.js Client - Integrate with your tests
- Gateway Configuration - Advanced gateway settings
Resources
Section titled “Resources”- Website: www.vaultsandbox.com
- GitHub Gateway: github.com/vaultsandbox/gateway
- Docker Hub: hub.docker.com/r/vaultsandbox/gateway