Docker Compose for MERN Stack
MongoDB, Express, React, Node.js. The classic JavaScript full-stack.
node mongodb react express fullstack
compose.yaml
services:
app:
build: .
ports:
- target: 3000
mode: ingress
environment:
- MONGODB_URI=mongodb://admin:${MONGO_INITDB_ROOT_PASSWORD}@db:27017/app?authSource=admin
- NODE_ENV=production
healthcheck:
test:
- CMD
- curl
- -f
- http://localhost:3000/
interval: 30s
timeout: 5s
retries: 3
depends_on:
- db
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
db:
image: mongo:7
ports:
- target: 27017
mode: host
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
healthcheck:
test:
- CMD
- mongosh
- --eval
- db.adminCommand('ping')
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
reservations:
cpus: "0.5"
memory: 256M
restart: unless-stopped
x-defang-mongodb: true
Services
- app .
- db mongo:7