# ============================================================================== # DOCKER COMPOSE TEMPLATE - BACKEND SERVICE # ============================================================================== # Template para servicios backend (Node.js, Python, etc.) # # USO: # 1. Copiar a tu proyecto: cp template proyecto/docker/docker-compose.yml # 2. Reemplazar placeholders: # - {{SERVICE_NAME}} -> nombre del servicio (ej: gamilit-api) # - {{PORT}} -> puerto interno (ej: 3000) # - {{DOMAIN}} -> dominio Traefik (ej: api.gamilit.localhost) # - {{PROJECT}} -> nombre del proyecto (ej: gamilit) # 3. Ajustar segun necesidades # # REGLAS: # - Usar expose, NO ports # - Redes deben ser external: true # - Incluir labels de Traefik # - Incluir healthcheck # ============================================================================== version: "3.8" # Anchors reutilizables x-logging: &default-logging driver: "json-file" options: max-size: "10m" max-file: "3" x-healthcheck: &default-healthcheck interval: 30s timeout: 5s retries: 3 start_period: 10s services: # ========================================================================== # BACKEND SERVICE # ========================================================================== {{SERVICE_NAME}}: build: context: ../apps/backend dockerfile: Dockerfile args: - NODE_ENV=${NODE_ENV:-development} container_name: {{SERVICE_NAME}} restart: unless-stopped # IMPORTANTE: usar expose, NO ports expose: - "{{PORT}}" # Variables de entorno environment: - NODE_ENV=${NODE_ENV:-development} - PORT={{PORT}} - DATABASE_URL=${DATABASE_URL} - REDIS_URL=${REDIS_URL:-redis://redis:6379} - JWT_SECRET=${JWT_SECRET} - JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-1d} - LOG_LEVEL=${LOG_LEVEL:-info} # Health check healthcheck: test: ["CMD", "curl", "-f", "http://localhost:{{PORT}}/health"] <<: *default-healthcheck # Labels para Traefik labels: - "traefik.enable=true" # Router - "traefik.http.routers.{{SERVICE_NAME}}.rule=Host(`{{DOMAIN}}`)" - "traefik.http.routers.{{SERVICE_NAME}}.entrypoints=web" # Service - "traefik.http.services.{{SERVICE_NAME}}.loadbalancer.server.port={{PORT}}" # Middlewares (opcional) # - "traefik.http.routers.{{SERVICE_NAME}}.middlewares=api-chain@file" # Redes networks: - {{PROJECT}}_${ENV:-local} - infra_shared # Logging logging: <<: *default-logging # Volumenes para desarrollo (opcional) # volumes: # - ../apps/backend/src:/app/src:ro # ============================================================================== # NETWORKS # ============================================================================== networks: {{PROJECT}}_${ENV:-local}: external: true infra_shared: external: true