desker/DOCKER_SETUP.md

2.5 KiB

Docker Setup Guide

This guide describes how to deploy the application using Docker and Docker Compose.

Prerequisites

  • Docker (20.10+)
  • Docker Compose (v2.0+)

Environment Variables

Create a .env file in the root directory. The following variables are supported (with their default values shown):

Variable Description Default
DB_USER PostgreSQL username postgres
DB_PASSWORD PostgreSQL password postgres
DB_NAME PostgreSQL database name hotdesking
DB_PORT_EXTERNAL External port for PostgreSQL 5433
API_PORT_EXTERNAL External port for the API 3000
WEB_PORT_EXTERNAL External port for the Web app 5173
JWT_SECRET Secret key for JWT signing super-secret-change-me
WEB_ORIGIN The origin of the web app (required by SvelteKit) http://localhost:5173
VITE_API_BASE_URL The URL of the API (for the web app) http://localhost:3000

Deployment Steps

  1. Copy the environment variables template:

    cp .env.example .env
    

    (Ensure you have a .env.example or create one from the table above).

  2. Build and start the containers:

    docker-compose up -d --build
    

    PostgreSQL and the API will start. The API will automatically run migrations during startup.

  3. (Optional) Seed the Database: If you have a seed script defined in apps/api/prisma/seed.ts:

    docker exec -it hotdesking_api npx prisma db seed
    

Important Note: PostgreSQL Initial Configuration

When you run docker-compose up for the first time, the PostgreSQL container uses the DB_USER, DB_PASSWORD, and DB_NAME values to initialize the database. These values are stored in a persistent volume (postgres_data).

If you change these environment variables after the first run, the database will not be re-initialized. This can cause connection errors (like role "desker" does not exist).

To apply new database credentials, you must remove the volume and start over:

docker-compose down -v
docker-compose up -d

Warning: This will delete all data in your database.

  1. Access the Applications:

Development with Docker

To watch logs:

docker-compose logs -f

To stop the applications:

docker-compose down