Skip to content

How to Deploy ELoyer with Docker and Docker Compose

  • by

This guide explains how to deploy ELoyer using Docker and Docker Compose with PostgreSQL. Containerization provides a consistent deployment environment and makes application updates easier to manage.

Prerequisites

Before deploying ELoyer, make sure your server has:

  • A Linux VPS
  • Root or sudo access
  • Docker
  • Docker Compose
  • A domain name for production use
  • SSH access

Step 1 — Install Docker

Install Docker:

curl -fsSL https://get.docker.com | sh

Add your current user to the Docker group:

sudo usermod -aG docker $USER

Log out and back in for the group change to take effect.

Verify Docker:

docker --version

Step 2 — Install Docker Compose

Install the Docker Compose plugin:

sudo apt install -y docker-compose-plugin

Verify:

docker compose version

Step 3 — Create the ELoyer Dockerfile

In the ELoyer project root, create:

Dockerfile

Add:

FROM node:20-alpine AS builder

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .
RUN npm run build

FROM node:20-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --omit=dev

COPY --from=builder /app/dist ./dist
COPY backend ./backend
COPY server.js .

EXPOSE 8080

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

This creates a production Docker image for ELoyer containing the compiled frontend and required backend files.

Step 4 — Create Docker Compose Configuration

Create:

docker-compose.yml

Add:

services:
  db:
    image: postgres:16-alpine
    restart: always
    environment:
      POSTGRES_USER: eloyer_user
      POSTGRES_PASSWORD: StrongPassword123!
      POSTGRES_DB: eloyer
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U eloyer_user -d eloyer"]
      interval: 10s
      timeout: 5s
      retries: 5

  api:
    build: .
    restart: always
    depends_on:
      db:
        condition: service_healthy
    env_file:
      - .env
    environment:
      PGHOST: db
      PGPORT: 5432
      PGUSER: eloyer_user
      PGPASSWORD: StrongPassword123!
      PGDATABASE: eloyer
      DATABASE_URL: postgresql://eloyer_user:StrongPassword123!@db:5432/eloyer
      NODE_ENV: production
    ports:
      - "8080:8080"

volumes:
  pgdata:

Use a strong production password instead of the example password.

Step 5 — Configure the ELoyer Environment

Create or edit:

nano .env

Add:

NODE_ENV=production
FRONTEND_URL=https://yourdomain.com

Add any additional environment variables required by ELoyer.

Do not commit production secrets to Git.

Step 6 — Build and Start ELoyer

Build the Docker image and start the containers:

docker compose up -d --build

Check the running containers:

docker compose ps

View the ELoyer application logs:

docker compose logs api --tail 50

Step 7 — Test ELoyer

Test the application health endpoint:

curl http://localhost:8080/api/health

A successful response should look similar to:

{"status":"ok","service":"eloyer-api"}

Step 8 — Configure Nginx for ELoyer

For production, use Nginx as a reverse proxy.

Create:

nginx.conf

Add:

upstream eloyer_api {
    server api:8080;
}

server {
    listen 80;
    server_name yourdomain.com;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        proxy_pass http://eloyer_api;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Add an Nginx service to docker-compose.yml:

  nginx:
    image: nginx:alpine
    restart: always
    depends_on:
      - api
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - certbot-www:/var/www/certbot:ro
      - certbot-conf:/etc/letsencrypt:ro

volumes:
  pgdata:
  certbot-www:
  certbot-conf:

Restart the ELoyer containers:

docker compose up -d

Step 9 — Update ELoyer

When a new version of ELoyer is available, pull the latest code:

git pull origin main

Rebuild the application:

docker compose up -d --build --no-deps api

The PostgreSQL container remains running and the database data remains stored in the pgdata volume.

Step 10 — Back Up the ELoyer Database

Create a PostgreSQL backup:

docker exec eloyer-db-1 \
  pg_dump -U eloyer_user eloyer > backup-$(date +%F).sql

For production, schedule regular backups with cron or another automated backup system.