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.
Services Inclus
nginx
nginx:1.27-alpine
frontend
node:22-alpine
Variables d'Environnement :
backend
node:22-alpine
Variables d'Environnement :
mongodb
mongo:7
Variables d'Environnement :
YAML Généré
# 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
Informations Rapides
- Services
- 4
- Réseaux
- 2
- Volumes
- 7
Quand l'Utiliser
Ce modèle est idéal pour mettre en place un environnement mern stack Tous les services sont préconfigurés avec des healthchecks, des limites de ressources et des valeurs par défaut raisonnables. Personnalisez les variables d'environnement avant de déployer en production.
Conseils
- Changez tous les mots de passe par défaut avant le déploiement
- Vérifiez les limites de ressources pour votre matériel
- Ajoutez un reverse proxy pour le HTTPS en production
- Configurez des stratégies de sauvegarde pour les volumes de données