Docker Deployment - bym-refitted/backyard-monsters-refitted GitHub Wiki

🐳 Docker Deployment

You can deploy the server using Docker with our docker-compose configuration, supporting both local development and production environments.

Deployment Components

The deployment includes the following containerized services:

  • 🎮 API Server: Node.js web server built from our custom Dockerfile with multi-stage optimization
  • 💿 PostgreSQL 16: Modern relational database with advanced features and performance
  • 💿 Redis 8.0: High-performance caching and session storage
  • 🔧 pgAdmin 4: Web-based PostgreSQL administration interface (development only)
  • ⚙️ Database Initialization: Dedicated service for one-time database setup and migrations

Prerequisites

For All Platforms:
  1. Install Docker Desktop (includes Docker Compose)
Windows-Specific Requirements:

Docker Desktop handles most setup automatically, but you may need to:

System Requirements:

  • Windows 10 64-bit (version 1903+) or Windows 11
  • At least 4GB RAM (8GB+ recommended for your game server)

If Docker Desktop fails to start:

  1. Check Virtualization: Open Task Manager → Performance → CPU. Look for "Virtualization: Enabled"
    • If disabled, you'll need to enable it in your computer's BIOS/UEFI settings
  2. Enable Windows Features (if not automatically enabled):
    • Open "Turn Windows features on or off"
    • Enable: "Windows Subsystem for Linux" and "Virtual Machine Platform"
    • Restart your computer

Quick Test: After installing Docker Desktop, open Command Prompt and run:

docker --version

If this shows a version number, you're ready to go!

Setting It Up

1. Environment Configuration

Create your .env environment file:

cp .env.example .env

Important: The .env file contains default development values. Never use these defaults in production - update all credentials and secrets before deploying to production.

Key environment variables to customize:

  • SECRET_KEY: Generate a secure random key for session encryption
  • DB_PASSWORD: Set a strong database password
  • PGADMIN_EMAIL & PGADMIN_PASSWORD: Credentials for pgAdmin access
2. Development Deployment

For local development with all development tools:

# Start all services including pgAdmin and exposed ports
docker compose --profile dev up -d

This will start:

  • API server on port 3001
  • PostgreSQL on port 5432
  • Redis on port 6379
  • pgAdmin on port 8080
3. Production Deployment

For production with security-focused configuration:

# Production deployment with minimal exposure
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

Production deployment features:

  • API server exposed only on port 80
  • Database and Redis ports not exposed externally
  • pgAdmin disabled for security
  • Optimized resource limits and restart policies

Verification

After deployment, verify your services:

Development Environment:

  • API Server: Visit http://localhost:3001 to confirm the API is online
  • pgAdmin: Access http://localhost:8080 using your configured credentials
  • Database Health: Check logs with docker compose logs db
  • Redis Health: Verify with docker compose logs redis

Production Environment:

  • API Server: Visit http://localhost (port 80) to confirm the API is online
  • Service Status: Check all services with docker compose ps

Database Management

The database is automatically initialized on first startup. To manually run database operations:

# Run database migrations
docker compose run --rm db-init

# Access PostgreSQL directly
docker compose exec db psql -U postgres -d bym

# View database logs
docker compose logs db

Development Features

Hot Reload

The development setup includes hot-reload functionality:

  • Changes to files in the server/ directory automatically sync to the container
  • The API server restarts automatically when changes are detected
Resource Monitoring

All services have configured resource limits to prevent system overload:

  • API Server: 512MB memory limit
  • Database: 1GB memory limit
  • Redis: 128MB memory limit
  • pgAdmin: 256MB memory limit

Maintenance Commands

# View service status
docker compose ps

# View logs for specific service
docker compose logs web
docker compose logs db

# Stop all services
docker compose down

# Stop and remove volumes (⚠️ destroys data)
docker compose down -v

# Rebuild containers after code changes
docker compose build
docker compose up -d

# Update to latest images
docker compose pull
docker compose up -d

Troubleshooting

Common Issues:

  1. Database Connection Issues

    • Ensure the database is healthy: docker compose logs db
    • Check if initialization completed: docker compose logs db-init
  2. Port Conflicts

    • Modify port mappings in .env file if defaults conflict with existing services
    • Use docker compose ps to see which ports are in use
  3. Memory Issues

    • Resource limits may need adjustment based on your system
    • Monitor usage with docker stats
  4. Permission Issues

    • Ensure Docker has necessary permissions on your system
    • Check file ownership in mounted volumes

Security Notes

  • Never use default credentials in production
  • Always use HTTPS in production (configure reverse proxy like nginx)
  • Keep your Docker images updated with docker compose pull
  • Regularly backup your database using pg_dump
  • Monitor your containers for security updates

Connecting Your Game Client

Once the server is running, use the latest local release of the SWF file or compile it manually to connect to:

  • Development: http://localhost:3001
  • Production: Your configured domain/IP address