Docker Deployment
This document covers the Docker containerization and deployment configuration for iHospita HMS.
Container Architecture
┌─────────────────────────────────────────────────────────────────┐
│ DOCKER COMPOSE STACK │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Application Containers: │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ kong │ hms │ crm │ payment │ queue │ report │ keycloak │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ Data Containers: │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ postgres │ redis │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ Observability Containers: │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ prometheus │ loki │ grafana │ tempo │ alertmanager │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
Main Docker Compose
# docker-compose.yml
version: '3.8'
services:
# Database
postgres:
image: postgres:15-alpine
container_name: ihospita-postgres
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ihospita
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- ihospita-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER}"]
interval: 10s
timeout: 5s
retries: 5
# Cache
redis:
image: redis:7-alpine
container_name: ihospita-redis
command: redis-server --appendonly yes
volumes:
- redis_data:/data
ports:
- "6379:6379"
networks:
- ihospita-network
# HMS Service
hms-service:
build:
context: ./server
dockerfile: Dockerfile
args:
APP_NAME: hms
container_name: ihospita-hms
environment:
DATABASE_URL: ${DATABASE_URL}
REDIS_URL: ${REDIS_URL}
NODE_ENV: production
ports:
- "3000:3000"
depends_on:
- postgres
- redis
networks:
- ihospita-network
# CRM Service
crm-service:
build:
context: ./server
dockerfile: Dockerfile
args:
APP_NAME: crm
container_name: ihospita-crm
ports:
- "3001:3001"
depends_on:
- postgres
- redis
networks:
- ihospita-network
# Payment Service
payment-service:
build:
context: ./server
dockerfile: Dockerfile
args:
APP_NAME: payment
container_name: ihospita-payment
ports:
- "3002:3002"
depends_on:
- postgres
- redis
networks:
- ihospita-network
# Queue Service
queue-service:
build:
context: ./server
dockerfile: Dockerfile
args:
APP_NAME: queue
container_name: ihospita-queue
ports:
- "3003:3003"
depends_on:
- postgres
- redis
networks:
- ihospita-network
# Report Service
report-service:
build:
context: ./server
dockerfile: Dockerfile
args:
APP_NAME: report
container_name: ihospita-report
ports:
- "3004:3004"
depends_on:
- postgres
- redis
networks:
- ihospita-network
networks:
ihospita-network:
driver: bridge
volumes:
postgres_data:
redis_data:
Service Dockerfile
# server/Dockerfile
FROM node:18-alpine AS builder
WORKDIR /app
# Install dependencies
COPY package*.json ./
RUN npm ci
# Copy source
COPY . .
# Build
ARG APP_NAME
RUN npm run build ${APP_NAME}
# Production image
FROM node:18-alpine AS runner
WORKDIR /app
# Copy built files
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
ARG APP_NAME
ENV APP_NAME=${APP_NAME}
EXPOSE 3000
CMD ["node", "dist/apps/${APP_NAME}/main.js"]
Commands
Start All Services
docker-compose up -d
View Logs
docker-compose logs -f [service-name]
Stop All Services
docker-compose down
Rebuild Service
docker-compose build --no-cache [service-name]
docker-compose up -d [service-name]
Database Migration
docker-compose exec hms-service npx prisma migrate deploy
Environment Variables
Create a .env file:
# Database
DB_USER=ihospita
DB_PASSWORD=secure-password
DATABASE_URL=postgresql://ihospita:secure-password@postgres:5432/ihospita
# Redis
REDIS_URL=redis://redis:6379
# Keycloak
KEYCLOAK_URL=http://keycloak:8080
KEYCLOAK_ADMIN=admin
KEYCLOAK_ADMIN_PASSWORD=admin-password
# Kong
KONG_DB_PASSWORD=kong-password
# Grafana
GRAFANA_ADMIN_USER=admin
GRAFANA_ADMIN_PASSWORD=admin-password
Health Checks
All services expose a /health endpoint:
curl http://localhost:3000/health
Response:
{
"status": "ok",
"uptime": 12345,
"timestamp": "2025-01-01T00:00:00.000Z"
}