Production-Ready Docker Compose Boilerplate for Nginx, Node.js, and MongoDB
A clean, multi-container Docker Compose setup featuring automatic restart policies, environment isolated networks, and persistent volume mounts.
Overview & Problem Matrix
Manually configuring, updating, and linking separate database platforms, backend application servers, and reverse proxy layers across divergent development or staging hosting environments frequently triggers the classic, frustrating "it works on my machine" operational crisis.
Managing manual virtual networks, matching port cross-bindings, tracking volatile microservice dependency boot ordering, and orchestrating localized data persistence properties becomes completely unmanageable as your containerized application topography expands. You need a centralized orchestration blueprint that spins up an immutable, deterministic, multi-container topology with true network layer isolation.
Implementation Guide & Setup Steps
To initialize this hardened three-tier infrastructure stack inside your production environment nodes, complete these development steps:
- Build Out Workspace Directory Directories: Establish your targeted project root workspace layout structures to match your network container mount mappings precisely:
$ mkdir -p api nginx/conf.d nginx/certs
- Stage the Orchestration Template: Save the optimized YAML infrastructure layout detailed below directly inside your root workspace pathway as
docker-compose.yml:
$ touch docker-compose.yml
- Spin Up Your Isolated Daemon Stack: Deploy the entire container network infrastructure concurrently in a silent detached background tracking mode using your server engine:
$ docker compose up -d
- Audit Container Health Status Checkpoints: Monitor the automated orchestration startup sequences to verify that all system networks and service layers are up, healthy, and communicating accurately:
$ docker compose ps
services: # 1. Edge Layer: Reverse Proxy routing web traffic webserver: image: nginx:1.25-alpine container_name: web_proxy_edge restart: always ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./nginx/certs:/etc/nginx/certs:ro
depends_on: api_service: condition: service_healthy networks:
- frontend_network
# 2. Application Layer: Node.js runtime microservice bridging both spaces api_service: build: context: ./api dockerfile: Dockerfile container_name: node_api_runtime restart: unless-stopped environment:
- NODE_ENV=production
- MONGO_URI=mongodb://db_user:db_password@database_engine:27017/prod_db?authSource=admin
expose:
- "3000"
depends_on: database_engine: condition: service_healthy networks:
- frontend_network
- backend_network
healthcheck: test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"] interval: 15s timeout: 5s retries: 3 start_period: 10s
# 3. Storage Layer: Fully persistent MongoDB backend isolated deep in the stack database_engine: image: mongo:6.0 container_name: mongo_db_storage restart: always environment:
- MONGO_INITDB_ROOT_USERNAME=db_user
- MONGO_INITDB_ROOT_PASSWORD=db_password
volumes:
- mongodb_data_store:/data/db
expose:
- "27017"
networks:
- backend_network
healthcheck: test: ["CMD-SHELL", "echo 'db.runCommand(\"ping\").ok' | mongosh localhost:27017/test --quiet"] interval: 10s timeout: 5s retries: 3
Explicitly partition public-facing request routes from core infrastructure storage files
networks: frontend_network: driver: bridge backend_network: driver: bridge
Mount points guarantee structural database records survive application updates or host wipes
volumes: mongodb_data_store: driver: local
Community Engineering Notes
No technical implementations have been appended yet.