2026-08-07 18:37:23 +00:00
# Coolify Deployment & Port Allocation Fixes
2026-08-07 09:28:35 +00:00
2026-08-07 09:38:37 +00:00
This application consists of:
2026-08-07 10:35:45 +00:00
1. **Server Side** : Node.js + Express backend (`server.ts`) serving REST APIs, managing authentication, ledger reconciliation, audit logs, FX rates, SMTP dispatching, and financial reports.
2026-08-07 09:48:18 +00:00
2. **Database** : PostgreSQL (via `pg` connection pool) with automatic JSON fallback backup.
2026-08-07 16:19:17 +00:00
3. **Frontend** : React SPA served directly via Express in production on port `3000` .
2026-08-07 09:28:35 +00:00
---
2026-08-07 18:37:23 +00:00
## 🛑 Resolving "Bind for 0.0.0.0:3000 failed: port is already allocated"
2026-08-07 09:28:35 +00:00
2026-08-07 18:37:23 +00:00
### Cause of the Error
When deploying in Coolify or a multi-container Docker host, port `3000` on the host machine is frequently already taken by Coolify's internal service, another app, or a reverse proxy. Explicitly binding host port `3000:3000` causes Docker daemon to crash with:
`Error response from daemon: Bind for 0.0.0.0:3000 failed: port is already allocated`
2026-08-07 16:19:17 +00:00
2026-08-07 18:37:23 +00:00
### How It Is Fixed in This Repository
In `docker-compose.yml` , direct host port binding (`ports: - "3000:3000"`) has been replaced with container exposure (`expose: - "3000"`).
2026-08-07 16:19:17 +00:00
2026-08-07 18:37:23 +00:00
Coolify's Traefik reverse proxy routes external web traffic directly into the container on port `3000` via Docker's internal container network. No host port allocation is required!
2026-08-07 16:19:17 +00:00
---
2026-08-07 18:37:23 +00:00
## 🔧 Coolify UI Configuration Steps
1. **Set Container / Destination Port** :
- In Coolify UI under **Settings** -> **Port** or **Destination Port** : Set to `3000` .
2. **Set Health Check** :
- **Path**: `/api/health`
- **Port**: `3000`
- **Type**: HTTP or Docker native check
---
## 🚀 Quick Deployment Options in Coolify
2026-08-07 16:19:17 +00:00
### Option A: Docker Compose Deployment (App + Dedicated PostgreSQL)
2026-08-07 09:28:35 +00:00
2026-08-07 09:38:37 +00:00
1. **In Coolify Dashboard** :
- Click ** + Add Resource** -> **Docker Compose** .
2026-08-07 16:19:17 +00:00
- Point to your Git Repository or paste `docker-compose.yml` .
2026-08-07 09:38:37 +00:00
2. **Environment Variables** :
Add the following in Coolify:
```env
NODE_ENV=production
PORT=3000
POSTGRES_PASSWORD=your_custom_secure_password
2026-08-07 10:35:45 +00:00
2026-08-07 16:19:17 +00:00
# SMTP Email Settings (Optional)
2026-08-07 10:35:45 +00:00
SMTP_HOST=smtp.your-server.com
SMTP_PORT=587
SMTP_USER=alerts@networkbank.com
SMTP_PASS=your_smtp_password
SMTP_FROM="Balance Sheet Portal < noreply @ networkbank . com > "
SMTP_USE_TLS=true
2026-08-07 09:38:37 +00:00
```
2026-08-07 18:37:23 +00:00
3. **Deploy** : Coolify builds the app container (exposing port `3000` ) and provisions `postgres:16-alpine` .
2026-08-07 09:28:35 +00:00
---
2026-08-07 18:37:23 +00:00
### Option B: Standalone Application Container (Coolify Managed PostgreSQL)
2026-08-07 09:28:35 +00:00
2026-08-07 16:19:17 +00:00
1. **Create PostgreSQL Resource** :
2026-08-07 09:38:37 +00:00
- Click ** + Add Resource** -> **PostgreSQL** .
2026-08-07 18:37:23 +00:00
- Note internal connection string (e.g. `postgresql://postgres:pass@postgres-host:5432/balance_sheet_db` ).
2026-08-07 16:19:17 +00:00
2. **Create Dockerfile Application** :
- Add Git Repository as a **Dockerfile Application** .
- Set Environment Variables:
2026-08-07 09:28:35 +00:00
```env
2026-08-07 16:19:17 +00:00
NODE_ENV=production
2026-08-07 09:28:35 +00:00
PORT=3000
2026-08-07 16:19:17 +00:00
DATABASE_URL=postgresql://postgres:pass@postgres-host:5432/balance_sheet_db
2026-08-07 09:28:35 +00:00
```
2026-08-07 18:37:23 +00:00
- In Settings -> **Exposed Port / Container Port** : Set to `3000` .
2026-08-07 16:19:17 +00:00
- In Health Check: Set path to `/api/health` .
3. **Deploy** : Express connects directly to PostgreSQL and initializes required tables automatically.