MERN Stack
A full-featured MERN (MongoDB, Express, React, Node.js) development and production stack. MongoDB 7 runs with authentication enabled and a dedicated replica-set-ready configuration for change streams. The Node 22 backend uses volume mounts and nodemon for hot reload during development, while the React frontend runs its own dev server. Nginx acts as a unified reverse proxy routing /api requests to the Express backend and all other traffic to the React dev server. Network separation isolates the database on the backend network while only Nginx is publicly exposed.
Servizi Inclusi
nginx
nginx:1.27-alpine
frontend
node:22-alpine
Variabili d'Ambiente:
backend
node:22-alpine
Variabili d'Ambiente:
mongodb
mongo:7
Variabili d'Ambiente:
YAML Generato
# Generated by ComposeHub (composehub.dev)
name: mern-stack
services:
nginx:
image: nginx:1.27-alpine
restart: unless-stopped
ports:
- 80:80
volumes:
- nginx_conf:/etc/nginx/conf.d
networks:
- frontend
depends_on:
backend:
condition: service_healthy
frontend:
condition: service_started
healthcheck:
test:
- CMD
- curl
- "-f"
- http://localhost
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
deploy:
resources:
limits:
cpus: "0.50"
memory: 256M
reservations:
cpus: "0.10"
memory: 64M
labels:
com.composeforge.description: Nginx reverse proxy routing /api to backend and / to frontend
frontend:
image: node:22-alpine
restart: unless-stopped
command:
- sh
- "-c"
- npm install && npm run dev
working_dir: /app
expose:
- "5173"
volumes:
- frontend_src:/app
- frontend_node_modules:/app/node_modules
environment:
NODE_ENV: ${NODE_ENV:-development}
VITE_API_URL: ${VITE_API_URL:-/api}
networks:
- frontend
deploy:
resources:
limits:
cpus: "1.00"
memory: 512M
reservations:
cpus: "0.25"
memory: 128M
labels:
com.composeforge.description: React development server (Vite)
backend:
image: node:22-alpine
restart: unless-stopped
command:
- sh
- "-c"
- npm install && npx nodemon src/index.js
working_dir: /app
expose:
- "3000"
volumes:
- backend_src:/app
- backend_node_modules:/app/node_modules
environment:
NODE_ENV: ${NODE_ENV:-development}
PORT: ${BACKEND_PORT:-3000}
MONGODB_URI: mongodb://${MONGO_USER:-app}:${MONGO_PASSWORD:-changeme}@mongodb:27017/${MONGO_DB:-mernapp}?authSource=admin
JWT_SECRET: ${JWT_SECRET:-change-this-secret}
networks:
- frontend
- backend
depends_on:
mongodb:
condition: service_healthy
healthcheck:
test:
- CMD-SHELL
- wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
deploy:
resources:
limits:
cpus: "1.00"
memory: 512M
reservations:
cpus: "0.25"
memory: 128M
labels:
com.composeforge.description: Express.js API backend with hot reload
mongodb:
image: mongo:7
restart: unless-stopped
volumes:
- mongodb_data:/data/db
- mongodb_config:/data/configdb
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER:-app}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-changeme}
MONGO_INITDB_DATABASE: ${MONGO_DB:-mernapp}
networks:
- backend
healthcheck:
test:
- CMD
- mongosh
- "--eval"
- db.adminCommand('ping')
- "--quiet"
interval: 30s
timeout: 10s
retries: 5
start_period: 40s
deploy:
resources:
limits:
cpus: "1.00"
memory: 512M
reservations:
cpus: "0.25"
memory: 256M
labels:
com.composeforge.description: MongoDB 7 document database with authentication
networks:
frontend:
driver: bridge
backend:
driver: bridge
volumes:
nginx_conf:
driver: local
frontend_src:
driver: local
frontend_node_modules:
driver: local
backend_src:
driver: local
backend_node_modules:
driver: local
mongodb_data:
driver: local
mongodb_config:
driver: local
Informazioni Rapide
- Servizi
- 4
- Reti
- 2
- Volumi
- 7
Quando Usarlo
Questo template è ideale per configurare un ambiente mern stack Tutti i servizi sono preconfigurati con healthchecks, limiti di risorse e valori predefiniti sensati. Personalizza le variabili d'ambiente prima di fare il deploy in produzione.
Consigli
- Cambia tutte le password predefinite prima del deploy
- Verifica i limiti di risorse per il tuo hardware
- Aggiungi un reverse proxy per HTTPS in produzione
- Configura strategie di backup per i volumi di dati