← Catalog Matrix

Deployment Execution Blueprint

---
title: Multi-Container Production Orchestration with Docker Compose, Nginx, and Node.js
description: An infrastructure orchestration blueprint to containerize Node.js application containers reverse-proxied behind an isolated Nginx reverse proxy.
category: DevOps & Automation
slug: docker-compose-production-nginx-node
keywords: docker compose production ready layout, nginx nodejs docker architecture, containerize web application stack, multi container communication networking, dockerfile node build
---

Technical Context & Blueprints
Deploying independent applications straight to bare-metal servers creates massive environment friction. Dependency version conflicts, runtime variable collisions, and host file structure pollution can easily break your stack.

By wrapping your environment in an isolated multi-container architecture using Docker Compose, you can link your Node application layer to an automated Nginx proxy gateway container, ensuring identical execution states across staging, testing, and production servers.

Module 1: The Optimized Production Dockerfile
Save this layout file inside your core Node application path folder directory as ./app/Dockerfile:

# Use a slim, secured base engine tracking framework image
FROM node:20-alpine AS environment_builder

WORKDIR /usr/src/app

# Cache package installation layout configurations to accelerate subsequent project rebuild arrays
COPY package*.json ./
RUN npm ci --only=production

# Re-copy remaining local production module codes inside container instances
COPY . .

EXPOSE 3000
USER node

CMD ["node", "server.js"]

Module 2: The Infrastructure Blueprint Configuration (docker-compose.yml)
Save this orchestrator layout file inside your master project folder root directory path as ./docker-compose.yml:

version: '3.8'

networks:
  production_application_bridge:
    driver: bridge

services:
  # SERVICE NODE A: Node Application Core Instance
  node_backend_engine:
    build:
      context: ./app
      dockerfile: Dockerfile
    restart: always
    environment:
      - NODE_ENV=production
      - PORT=3000
    networks:
      - production_application_bridge

  # SERVICE NODE B: Gateway Proxy Engine Shield Layer
  nginx_gateway_proxy:
    image: nginx:alpine
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/production_routing.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - node_backend_engine
    networks:
      - production_application_bridge
      
Module 3: Embedded Nginx Configuration Routing (./nginx/production_routing.conf)

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        # Route internal container socket traffic using the container name defined in docker-compose
        proxy_pass http://node_backend_engine:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

# Compile dependencies and launch your multi-container environment instantly in background mode
docker-compose up -d --build