# Docker Compose Configuration for Production Deployment # This file is used by CI/CD to deploy the application on production servers # # Key differences from local docker-compose.yml: # - Uses pre-built image from registry (not local build) # - Includes resource limits and logging configuration # - More stringent health checks # - Production-grade restart policies # # Usage: # 1. This file is automatically copied to server by CI/CD workflow # 2. Server pulls image from registry: docker compose -f docker-compose.prod.yml pull # 3. Server starts container: docker compose -f docker-compose.prod.yml up -d # # Manual deployment (if CI/CD is not available): # ssh user@production-server # cd /opt/mypage # docker compose -f docker-compose.prod.yml pull # docker compose -f docker-compose.prod.yml up -d --force-recreate version: '3.8' services: mypage: # Use pre-built image from private registry # This image is built and pushed by the CI/CD workflow # Format: REGISTRY_URL/IMAGE_NAME:TAG image: repository.workspace:5000/mypage:latest container_name: mypage-prod # Restart policy: always restart on failure or server reboot # This ensures high availability in production restart: always # Port mapping: host:container # The application will be accessible at http://SERVER_IP:3030 # Usually, a reverse proxy (Caddy/Nginx) will forward traffic to this port ports: - "3030:3030" # Production environment variables environment: - NODE_ENV=production - NEXT_TELEMETRY_DISABLED=1 - PORT=3030 - HOSTNAME=0.0.0.0 # Add any other production-specific environment variables here # Example: # - DATABASE_URL=postgresql://user:pass@db:5432/mypage # - REDIS_URL=redis://redis:6379 # Persistent volumes for logs (optional) # Uncomment if your application writes logs volumes: - ./data/logs:/app/logs # Health check configuration # Docker monitors the application and marks it unhealthy if checks fail # If container is unhealthy, restart policy will trigger a restart healthcheck: test: ["CMD-SHELL", "curl -f http://localhost:3030/ || exit 1"] interval: 30s # Check every 30 seconds timeout: 10s # Wait up to 10 seconds for response retries: 3 # Mark unhealthy after 3 consecutive failures start_period: 40s # Grace period during container startup # Resource limits for production # Prevents container from consuming all server resources # deploy: # resources: # limits: # cpus: '1.0' # Maximum 1 CPU core # memory: 512M # Maximum 512MB RAM # reservations: # cpus: '0.25' # Reserve at least 0.25 CPU cores # memory: 256M # Reserve at least 256MB RAM # Network configuration networks: - mypage-network # Logging configuration # Prevents logs from consuming all disk space logging: driver: "json-file" options: max-size: "10m" # Maximum 10MB per log file max-file: "3" # Keep only 3 log files (30MB total) # Network definition networks: mypage-network: driver: bridge # ============================================ # Production Deployment Commands # ============================================ # # Pull latest image from registry: # docker compose -f docker-compose.prod.yml pull # # Start/update containers: # docker compose -f docker-compose.prod.yml up -d --force-recreate # # View logs: # docker compose -f docker-compose.prod.yml logs -f mypage # # Check health status: # docker inspect mypage-prod | grep -A 10 Health # # Stop containers: # docker compose -f docker-compose.prod.yml down # # Restart containers: # docker compose -f docker-compose.prod.yml restart # # Remove old/unused images (cleanup): # docker image prune -f # # ============================================ # Troubleshooting # ============================================ # # If container keeps restarting: # 1. Check logs: docker compose -f docker-compose.prod.yml logs --tail=100 # 2. Check health: docker inspect mypage-prod | grep -A 10 Health # 3. Verify port is not already in use: netstat -tulpn | grep 3030 # 4. Check resource usage: docker stats mypage-prod # # If health check fails: # 1. Test manually: docker exec mypage-prod curl -f http://localhost:3030/ # 2. Check if Next.js server is running: docker exec mypage-prod ps aux # 3. Verify environment variables: docker exec mypage-prod env