services: backend: build: context: ./backend dockerfile: Dockerfile container_name: threat-model-ai-backend user: "${UID:-502}:${GID:-502}" # SEC-004: bind the published port to loopback by default so the API is not # exposed on every host interface. The reverse of the container's internal # HOST (below) is deliberate: the port is only reachable via the host's # localhost. Override to "0.0.0.0:3001:3001" (or a specific interface, e.g. # "192.168.1.10:3001:3001") when the service must be reachable off-host. ports: - "127.0.0.1:3001:3001" environment: - NODE_ENV=production - PORT=3001 # SEC-003: backend fails to boot in NODE_ENV=production without this. # Generate with: openssl rand -hex 32 and put in .env. # Intentionally NOT using ${JWT_SECRET:?...} so `docker-compose down`, # `ps`, and `logs` keep working when the var is unset. - JWT_SECRET=${JWT_SECRET} # Bind to 0.0.0.0 INSIDE the container so the published port (3001:3001) # is reachable. This is safe: the container's network is isolated, and an # adversary would still need to traverse the host firewall + docker's port # mapping. Plain `npm run dev`/`npm start` defaults to 127.0.0.1 (loopback). - HOST=0.0.0.0 volumes: - ./backend/data:/app/data - ./backend/uploads:/app/uploads - ./backend/work_dir:/app/work_dir - ./backend/threat-modeling-reports:/app/threat-modeling-reports - ./backend/logs:/app/logs logging: driver: "json-file" options: max-size: "10m" max-file: "3" restart: unless-stopped stop_grace_period: 30s healthcheck: test: ["CMD-SHELL", "node -e \"require('http').get('http://localhost:3001/api/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))\""] interval: 30s timeout: 3s retries: 3 start_period: 5s deploy: resources: limits: cpus: '1' memory: 4G pids: 4096 reservations: cpus: '1' memory: 2G security_opt: - no-new-privileges:true cap_drop: - ALL cap_add: - NET_BIND_SERVICE - SETUID - SETGID - CHOWN - DAC_OVERRIDE - FOWNER - SYS_PTRACE - KILL frontend: build: context: ./frontend dockerfile: Dockerfile args: - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://localhost:3001/api} container_name: threat-model-ai-frontend user: "${UID:-502}:${GID:-502}" ports: - "127.0.0.1:3000:3000" environment: - NODE_ENV=production - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://localhost:3001/api} logging: driver: "json-file" options: max-size: "10m" max-file: "3" depends_on: backend: condition: service_healthy restart: unless-stopped stop_grace_period: 120s deploy: resources: limits: cpus: '1' memory: 2G reservations: cpus: '0.25' memory: 256M security_opt: - no-new-privileges:true cap_drop: - ALL cap_add: - NET_BIND_SERVICE networks: default: name: threat-model-ai-network