đŸŗ Multi-Container Microservices Architecture

Docker Compose Orchestration - Scalable Microservices with Container Networking

5
Active Containers
5
Running Services
2
Networks
3
Volumes

đŸ—ī¸ Microservices Architecture

This project demonstrates a complete multi-container microservices architecture using Docker Compose. The system includes a Node.js API, MongoDB database, Redis cache, and Nginx reverse proxy, all orchestrated with container networking, health checks, and persistent volumes.

🌐
Nginx Proxy
RUNNING
Reverse proxy and load balancer handling incoming HTTP requests and routing to backend services.
Port: 80:80
Image: nginx:alpine
⚡
Node.js API
RUNNING
RESTful API service built with Express.js, handling business logic and database operations.
Port: 3000:3000
Replicas: 2
🍃
MongoDB
RUNNING
NoSQL database for persistent data storage with volume mounting for data persistence.
Port: 27017:27017
Volume: mongo-data
🔴
Redis Cache
RUNNING
In-memory data store for caching and session management, improving API response times.
Port: 6379:6379
Volume: redis-data
📊
Worker Service
RUNNING
Background worker processing asynchronous tasks and scheduled jobs from message queue.
Type: Background
Image: node:18-alpine

🔧 Service Management

Container Status
CONTAINER ID IMAGE STATUS PORTS NAMES a1b2c3d4e5f6 nginx:alpine Up 2 hours 0.0.0.0:80->80/tcp proxy b2c3d4e5f6a7 node:18-alpine Up 2 hours 0.0.0.0:3000->3000/tcp api-1 c3d4e5f6a7b8 node:18-alpine Up 2 hours 3000/tcp api-2 d4e5f6a7b8c9 mongo:6 Up 2 hours 0.0.0.0:27017->27017 mongodb e5f6a7b8c9d0 redis:alpine Up 2 hours 0.0.0.0:6379->6379 redis
Resource Usage
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O proxy 0.12% 12.5MiB / 2GiB 0.61% 1.2MB / 890KB api-1 2.45% 156MiB / 512MiB 30.47% 2.1MB / 1.8MB api-2 2.38% 152MiB / 512MiB 29.69% 2.0MB / 1.7MB mongodb 1.23% 342MiB / 1GiB 33.40% 1.5MB / 1.2MB redis 0.45% 8.2MiB / 256MiB 3.20% 450KB / 380KB

🌐 Container Networking

Network Architecture

🌐
External Network
Port 80
🔀
Nginx Proxy
frontend-net
⚡
API Service
backend-net
⚡
API Replica
backend-net
🍃
MongoDB
backend-net
🔴
Redis
backend-net
Network Configuration
networks: frontend-net: driver: bridge ipam: config: - subnet: 172.20.0.0/16 backend-net: driver: bridge internal: true ipam: config: - subnet: 172.21.0.0/16

📝 Docker Compose Configuration

docker-compose.yml
version: '3.8' services: proxy: image: nginx:alpine container_name: proxy ports: - "80:80" volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro networks: - frontend-net depends_on: - api restart: unless-stopped healthcheck: test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/health"] interval: 30s timeout: 10s retries: 3 api: image: node:18-alpine container_name: api working_dir: /app volumes: - ./api:/app - node_modules:/app/node_modules environment: - NODE_ENV=production - MONGODB_URI=mongodb://mongodb:27017/myapp - REDIS_URL=redis://redis:6379 networks: - frontend-net - backend-net depends_on: - mongodb - redis command: npm start deploy: replicas: 2 restart_policy: condition: on-failure max_attempts: 3 healthcheck: test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000/health"] interval: 30s timeout: 10s retries: 3 mongodb: image: mongo:6 container_name: mongodb environment: - MONGO_INITDB_ROOT_USERNAME=admin - MONGO_INITDB_ROOT_PASSWORD=secret volumes: - mongo-data:/data/db - mongo-config:/data/configdb networks: - backend-net restart: unless-stopped healthcheck: test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"] interval: 30s timeout: 10s retries: 3 redis: image: redis:alpine container_name: redis command: redis-server --appendonly yes volumes: - redis-data:/data networks: - backend-net restart: unless-stopped healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 30s timeout: 10s retries: 3 worker: image: node:18-alpine container_name: worker working_dir: /app volumes: - ./worker:/app environment: - NODE_ENV=production - MONGODB_URI=mongodb://mongodb:27017/myapp - REDIS_URL=redis://redis:6379 networks: - backend-net depends_on: - mongodb - redis command: npm start restart: unless-stopped networks: frontend-net: driver: bridge backend-net: driver: bridge internal: true volumes: mongo-data: mongo-config: redis-data: node_modules:
Common Docker Commands
# Start all services docker-compose up -d # View running containers docker-compose ps # View logs docker-compose logs -f # Scale API service docker-compose up -d --scale api=3 # Stop all services docker-compose down # Rebuild and start docker-compose up -d --build # Remove volumes docker-compose down -v

📋 Container Logs

[proxy] 2024-01-20 15:30:12 - Nginx started successfully on port 80
[api-1] 2024-01-20 15:30:15 - Server listening on port 3000
[api-2] 2024-01-20 15:30:15 - Server listening on port 3000
[mongodb] 2024-01-20 15:30:10 - MongoDB started successfully
[mongodb] 2024-01-20 15:30:11 - Waiting for connections on port 27017
[redis] 2024-01-20 15:30:08 - Redis server started
[redis] 2024-01-20 15:30:09 - Ready to accept connections
[worker] 2024-01-20 15:30:18 - Worker service initialized
[api-1] 2024-01-20 15:31:45 - GET /api/users - 200 OK (23ms)
[api-2] 2024-01-20 15:31:47 - POST /api/users - 201 Created (45ms)
[mongodb] 2024-01-20 15:31:47 - Connection accepted from api-2
[api-1] 2024-01-20 15:32:12 - Cache hit for user:123
[redis] 2024-01-20 15:32:12 - GET user:123
[worker] 2024-01-20 15:32:30 - Processing background job: email-notification
[worker] 2024-01-20 15:32:35 - Job completed successfully
[proxy] 2024-01-20 15:33:00 - Load balanced request to api-1
[api-2] 2024-01-20 15:33:15 - Slow query detected (234ms)
[mongodb] 2024-01-20 15:33:45 - Index created on users collection
[api-1] 2024-01-20 15:34:00 - Health check passed
[mongodb] 2024-01-20 15:34:01 - Health check passed