Docker Deployment
Production-ready Docker deployment guide for DesterLib.
Production Setup
Section titled “Production Setup”Quick Setup (Easiest)
Section titled “Quick Setup (Easiest)”macOS/Linux:
curl -fsSL https://raw.githubusercontent.com/DesterLib/desterlib/main/scripts/setup/unix.sh | bashWindows (PowerShell):
iwr -useb https://raw.githubusercontent.com/DesterLib/desterlib/main/scripts/setup/windows.ps1 | iexThe setup script configures production-ready settings by default:
- Sets
NODE_ENV=production - Configures restart policies
- Sets up health checks
- Uses production database
Manual Setup
Section titled “Manual Setup”git clone https://github.com/DesterLib/desterlib.gitcd desterlib
# Create .env in apps/api/DATABASE_URL=postgresql://desterlib:STRONG_PASSWORD@postgres:5432/desterlib?schema=publicNODE_ENV=productionPORT=3001
# Start in production modedocker compose up -dProduction Best Practices
Section titled “Production Best Practices”Resource Limits
Section titled “Resource Limits”Add resource limits to prevent overconsumption:
Edit docker-compose.yml:
api: image: desterlib/api:latest deploy: resources: limits: cpus: "2.0" memory: 2G reservations: memory: 512M
postgres: image: postgres:15-alpine deploy: resources: limits: memory: 1G reservations: memory: 256MPersistent Volumes
Section titled “Persistent Volumes”Ensure data persists across container restarts:
volumes: postgres_data: driver: local driver_opts: type: none device: /path/to/persistent/storage o: bindHealth Checks
Section titled “Health Checks”Both services include health checks by default:
api: healthcheck: test: [ "CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1", ] interval: 30s timeout: 10s retries: 3 start_period: 40s
postgres: healthcheck: test: ["CMD-SHELL", "pg_isready -U desterlib"] interval: 10s timeout: 5s retries: 5Networking
Section titled “Networking”Expose to Network
Section titled “Expose to Network”The default configuration binds to 0.0.0.0:
ports: - "0.0.0.0:3001:3001"This allows connections from:
- Local machine
- LAN devices
- Remote clients (if port forwarded)
Internal Network Only
Section titled “Internal Network Only”For localhost-only access:
ports: - "127.0.0.1:3001:3001"Reverse Proxy
Section titled “Reverse Proxy”nginx.conf:
server { listen 80; server_name desterlib.yourdomain.com;
location / { proxy_pass http://localhost:3001; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
# WebSocket support location /ws { proxy_pass http://localhost:3001; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; }}Caddy (Automatic HTTPS)
Section titled “Caddy (Automatic HTTPS)”Caddyfile:
desterlib.yourdomain.com { reverse_proxy localhost:3001}Caddy automatically handles:
- HTTPS certificates (Let’s Encrypt)
- Certificate renewal
- HTTP to HTTPS redirect
Traefik
Section titled “Traefik”docker-compose.yml:
api: image: desterlib/api:latest labels: - "traefik.enable=true" - "traefik.http.routers.desterlib.rule=Host(`desterlib.yourdomain.com`)" - "traefik.http.routers.desterlib.entrypoints=websecure" - "traefik.http.routers.desterlib.tls.certresolver=myresolver"Logging
Section titled “Logging”Configure Log Levels
Section titled “Configure Log Levels”Set in environment:
NODE_ENV=production # Less verbose# orNODE_ENV=development # More verbose (debug logs)Log Drivers
Section titled “Log Drivers”Use JSON log format:
api: image: desterlib/api:latest logging: driver: "json-file" options: max-size: "10m" max-file: "3"External Logging
Section titled “External Logging”To syslog:
logging: driver: syslog options: syslog-address: "tcp://192.168.1.100:514"To file:
logging: driver: json-file options: max-size: "100m" max-file: "5" compress: "true"Monitoring
Section titled “Monitoring”Docker Health Checks
Section titled “Docker Health Checks”View health status:
docker psLook for “healthy” in the STATUS column.
Prometheus Metrics (Future)
Section titled “Prometheus Metrics (Future)”Prometheus integration is planned for future releases.
Security
Section titled “Security”Network Isolation
Section titled “Network Isolation”Create isolated Docker network:
networks: desterlib-net: driver: bridge internal: false
services: postgres: networks: - desterlib-net
api: networks: - desterlib-netRead-Only Media Mount
Section titled “Read-Only Media Mount”Media is mounted read-only for security:
volumes: - /path/to/media:/media:ro # :ro = read-onlyNon-Root User (Future)
Section titled “Non-Root User (Future)”Running as non-root user is planned for future releases.
Scaling
Section titled “Scaling”Single Server
Section titled “Single Server”Current setup is designed for single-server deployment:
- One API instance
- One PostgreSQL instance
- Suitable for personal use (1-100 users)
Future: Multi-Instance
Section titled “Future: Multi-Instance”Horizontal scaling is planned for future releases with:
- Multiple API instances behind load balancer
- Shared PostgreSQL database
- Redis for session management
Backup in Production
Section titled “Backup in Production”Automated Database Backups
Section titled “Automated Database Backups”Create backup service:
# Add to docker-compose.ymlbackup: image: postgres:15-alpine depends_on: - postgres volumes: - ./backups:/backups - postgres_data:/var/lib/postgresql/data:ro command: > sh -c "while true; do pg_dump -U desterlib -h postgres desterlib > /backups/backup-$$(date +%Y%m%d-%H%M%S).sql sleep 86400 done" restart: unless-stoppedThis creates daily backups in ./backups/.
Updating in Production
Section titled “Updating in Production”Zero-Downtime Updates (Future)
Section titled “Zero-Downtime Updates (Future)”Currently, updates require brief downtime:
cd ~/.desterlibdocker compose pulldocker compose up -dDowntime: ~10-30 seconds during container restart.
Scheduled Maintenance
Section titled “Scheduled Maintenance”Recommend updating during low-usage times:
# Schedule with cron at 3 AM0 3 * * 0 cd ~/.desterlib && docker compose pull && docker compose up -dTroubleshooting
Section titled “Troubleshooting”Container Keeps Restarting
Section titled “Container Keeps Restarting”Check logs:
docker compose logs --tail=100 apiCommon causes:
- Database connection failure
- Invalid environment variables
- Port already in use
- Missing required config
High Memory Usage
Section titled “High Memory Usage”Check resource usage:
docker statsIf too high:
- Add memory limits (see Resource Limits above)
- Check for memory leaks in logs
- Restart containers:
docker compose restart
Database Performance
Section titled “Database Performance”For large libraries (10,000+ items):
-
Increase database resources:
postgres:deploy:resources:limits:memory: 2G -
Optimize PostgreSQL:
postgres:command: postgres -c shared_buffers=256MB -c max_connections=200
Related Documentation
Section titled “Related Documentation”- Installation Guide - Initial setup