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.
Enthaltene Services
nginx
nginx:1.27-alpine
frontend
node:22-alpine
Umgebungsvariablen:
backend
node:22-alpine
Umgebungsvariablen:
mongodb
mongo:7
Umgebungsvariablen:
Generiertes YAML
# 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
Kurzinfo
- Services
- 4
- Netzwerke
- 2
- Volumes
- 7
Wann verwenden
Dieses Template ist ideal für die Einrichtung einer mern stack Umgebung. Alle Services sind mit Healthchecks, Ressourcenlimits und sinnvollen Standardwerten vorkonfiguriert. Passen Sie die Umgebungsvariablen an, bevor Sie in Produktion gehen.
Tipps
- Ändern Sie alle Standardpasswörter vor dem Deployment
- Überprüfen Sie die Ressourcenlimits für Ihre Hardware
- Fügen Sie einen Reverse Proxy für HTTPS in Produktion hinzu
- Konfigurieren Sie Backup-Strategien für Daten-Volumes