Docker & PM2 Deployment Blueprint
This guide outlines the professional deployment workflows for your generated project, covering containerized environments with Docker and direct process management via PM2.
Choose Your Deployment Mode
| Mode | Strategy | Best For | Why? |
|---|---|---|---|
| ** Docker** | Containerization | CI/CD, Cloud, Multi-Cloud | Environment consistency. |
| ** PM2** | Process Management | VPS, Dedicated Servers | Lowest overhead, native speed. |
Docker Deployment
The project includes a Multi-Stage Dockerfile optimized for production images.
1. Running Locally (Development)
To run the Node.js application locally while using Docker for the infrastructure (Database, Redis, Kafka, etc.):
# Start infrastructure
docker-compose up -d db redis kafka
# Start the application
npm run dev2. Running the App Container with Compose Infrastructure
If you want to run the application itself inside a Docker container:
# Ensure infrastructure is running
docker-compose up -d
# Build Production Image
docker build -t your-app-name .
# Run Container (attached to the compose network)
docker run -p 3000:3000 --network your-app-name_default \
-e DB_HOST=db \
-e REDIS_HOST=redis \
your-app-name# Ensure infrastructure is running
docker-compose up -d
# Build Production Image
docker build -t your-app-name .
# Run Container (attached to the compose network)
docker run -p 3000:3000 --network your-app-name_default \
-e REDIS_HOST=redis \
-e KAFKA_BROKER=kafka:29092 \
your-app-name# Build Production Image
docker build -t your-app-name .
# Run Container
docker run -p 3000:3000 your-app-namePM2 Deployment (VPS/EC2)
The project is pre-configured for direct deployment to a VPS/EC2 instance using PM2 (via ecosystem.config.js).
1. Deployment Steps
Install dependencies:
bashnpm installStart Infrastructure (background services):
bashdocker-compose up -d db redis kafkaWait 5-10s for the database to fully initialize.
Deploy the App using PM2 in Cluster Mode:
bash# Build project and deploy npm run build npm run deploybash# Deploy directly npm run deploy
2. Process Management
| Command | Action |
|---|---|
npx pm2 logs | Check real-time application logs |
npx pm2 status | Check application status |
npx pm2 stop all | Stop all processes |
npx pm2 delete your-app-name | Remove application from PM2 |
CLEANUP
When shutting down, remember to stop the infrastructure:
docker-compose down