docker.recipes

MEAN Stack

intermediate

MongoDB, Express, Angular, Node.js full-stack setup.

Overview

The MEAN stack combines MongoDB, Express.js, Angular, and Node.js into a JavaScript-first full-stack development platform. MongoDB serves as the document-oriented NoSQL database, storing data in flexible JSON-like documents that align naturally with JavaScript objects. Express.js provides the web application framework running on Node.js for the backend API, while Angular handles the frontend single-page application with TypeScript support and component-based architecture. This Docker configuration creates a three-tier architecture where Angular serves the client-side application on port 4200, Express.js handles API requests on port 3000, and MongoDB manages data persistence on the internal network. The stack leverages JavaScript throughout the entire application lifecycle, from database queries using MongoDB's native JavaScript drivers to frontend rendering with Angular's TypeScript-compiled components. The containerized approach isolates each service while maintaining communication through a dedicated Docker network. Developers building modern web applications, startups requiring rapid prototyping capabilities, and teams seeking a unified JavaScript development experience will find this stack particularly valuable. The MEAN architecture excels in scenarios requiring real-time data updates, content management systems, and applications with evolving schemas where MongoDB's flexibility shines alongside Angular's dynamic frontend capabilities.

Key Features

  • Document-based data storage with MongoDB's flexible JSON-like schema design
  • Real-time data binding between Angular components and Express.js API endpoints
  • MongoDB aggregation framework for complex data analytics and reporting
  • Angular's component-based architecture with dependency injection and routing
  • Express.js middleware ecosystem for authentication, logging, and request processing
  • Node.js event-driven architecture enabling high-concurrent connection handling
  • MongoDB change streams for real-time application updates and notifications
  • Angular CLI integration for rapid component generation and build optimization

Common Use Cases

  • 1Content management systems requiring flexible document schemas and rich user interfaces
  • 2Social media platforms with real-time feeds, user interactions, and dynamic content
  • 3E-commerce applications managing product catalogs, user profiles, and order processing
  • 4Project management tools with collaborative features and document storage
  • 5Blog platforms and publishing systems with rich text editing and media management
  • 6Dashboard applications displaying real-time analytics and business intelligence
  • 7Learning management systems with course content, user progress tracking, and assessments

Prerequisites

  • Docker and Docker Compose installed with minimum 4GB RAM available for containers
  • Angular CLI installed globally for frontend development and build processes
  • Node.js and npm knowledge for Express.js backend development and package management
  • Ports 3000, 4200, and 27017 available on the host system
  • Basic understanding of TypeScript for Angular component development
  • MongoDB query syntax familiarity for database operations and aggregation pipelines

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 frontend:
3 build:
4 context: ./frontend
5 dockerfile: Dockerfile
6 container_name: angular-frontend
7 ports:
8 - "4200:4200"
9 networks:
10 - mean
11
12 backend:
13 build:
14 context: ./backend
15 dockerfile: Dockerfile
16 container_name: express-backend
17 environment:
18 MONGODB_URI: mongodb://mongodb:27017/${DB_NAME}
19 ports:
20 - "3000:3000"
21 depends_on:
22 - mongodb
23 networks:
24 - mean
25
26 mongodb:
27 image: mongo:7
28 container_name: mongodb
29 volumes:
30 - mongodb_data:/data/db
31 networks:
32 - mean
33
34volumes:
35 mongodb_data:
36
37networks:
38 mean:
39 driver: bridge

.env Template

.env
1DB_NAME=meanapp

Usage Notes

  1. 1Docs: https://angular.io/guide/setup-local
  2. 2Create frontend/ with ng new (Angular CLI)
  3. 3Create backend/ with Express.js API
  4. 4Frontend at http://localhost:4200, API at http://localhost:3000
  5. 5MongoDB connection: mongodb://mongodb:27017/dbname
  6. 6Use HttpClient module for API requests

Individual Services(3 services)

Copy individual services to mix and match with your existing compose files.

frontend
frontend:
  build:
    context: ./frontend
    dockerfile: Dockerfile
  container_name: angular-frontend
  ports:
    - "4200:4200"
  networks:
    - mean
backend
backend:
  build:
    context: ./backend
    dockerfile: Dockerfile
  container_name: express-backend
  environment:
    MONGODB_URI: mongodb://mongodb:27017/${DB_NAME}
  ports:
    - "3000:3000"
  depends_on:
    - mongodb
  networks:
    - mean
mongodb
mongodb:
  image: mongo:7
  container_name: mongodb
  volumes:
    - mongodb_data:/data/db
  networks:
    - mean

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 frontend:
5 build:
6 context: ./frontend
7 dockerfile: Dockerfile
8 container_name: angular-frontend
9 ports:
10 - "4200:4200"
11 networks:
12 - mean
13
14 backend:
15 build:
16 context: ./backend
17 dockerfile: Dockerfile
18 container_name: express-backend
19 environment:
20 MONGODB_URI: mongodb://mongodb:27017/${DB_NAME}
21 ports:
22 - "3000:3000"
23 depends_on:
24 - mongodb
25 networks:
26 - mean
27
28 mongodb:
29 image: mongo:7
30 container_name: mongodb
31 volumes:
32 - mongodb_data:/data/db
33 networks:
34 - mean
35
36volumes:
37 mongodb_data:
38
39networks:
40 mean:
41 driver: bridge
42EOF
43
44# 2. Create the .env file
45cat > .env << 'EOF'
46DB_NAME=meanapp
47EOF
48
49# 3. Start the services
50docker compose up -d
51
52# 4. View logs
53docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/mean-stack/run | bash

Troubleshooting

  • Angular build fails with memory errors: Increase Docker container memory limits or add NODE_OPTIONS=--max-old-space-size=4096 to frontend environment
  • MongoDB connection refused from Express.js: Ensure backend service depends_on mongodb and uses hostname 'mongodb' instead of 'localhost' in connection string
  • CORS errors when Angular calls Express API: Configure Express.js with cors middleware allowing origin http://localhost:4200
  • Frontend container exits immediately: Verify Angular CLI is properly installed and package.json contains valid start script for development server
  • MongoDB data loss after container restart: Ensure mongodb_data volume is properly mounted to /data/db and has sufficient disk space
  • Express.js crashes with module not found: Check that backend Dockerfile includes npm install step and all dependencies are listed in package.json

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space