Raypx

Docker

Building and running Raypx with Docker.

Raypx ships a multi-stage Dockerfile that produces a minimal production image. The image contains only the Nitro server output and Node.js 22 — no build tools, no source code, no node_modules.

Dockerfile Overview

The Dockerfile uses four stages:

base       → Node.js 22 Alpine + pnpm 10.33.0
deps       → Install dependencies (cached layer)
build      → Full production build
runner     → Copy .output/ only

Each stage prints its disk size with du -sh /app to help track layer bloat during development.

Stage 1: Base

FROM node:22-alpine AS base
RUN corepack enable && corepack prepare pnpm@10.33.0 --activate
WORKDIR /app

Enables Corepack and pins pnpm to the same version used by the project.

Stage 2: Dependencies

FROM base AS deps
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
COPY packages/ packages/
COPY tooling/ tooling/
COPY content/ content/
RUN pnpm install --frozen-lockfile --ignore-scripts

Installs all workspace dependencies. This layer is cached as long as pnpm-lock.yaml does not change.

Stage 3: Build

FROM deps AS build
COPY . .
RUN NODE_ENV=production pnpm build

Runs the full Vite production build. The output goes to .output/.

Stage 4: Runner

FROM base AS runner
COPY --from=build /app/.output .output
ENV HOST=0.0.0.0
ENV PORT=3001
EXPOSE 3001
CMD ["node", ".output/server/index.mjs"]

Starts fresh from the base image and copies only the .output/ directory. This keeps the final image small.

Building the Image

docker build -t raypx .

Running the Container

docker run -p 3001:3001 --env-file .env raypx

Always pass environment variables via --env-file or -e flags. Never bake secrets into the image.

Docker Compose

Here is a complete docker-compose.yml that runs Raypx alongside PostgreSQL:

services:
  app:
    build: .
    ports:
      - "3001:3001"
    env_file: .env
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - ./.storage:/app/.storage
    restart: unless-stopped

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: raypx
      POSTGRES_PASSWORD: raypx
      POSTGRES_DB: raypx
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U raypx"]
      interval: 5s
      timeout: 5s
      retries: 5

volumes:
  pgdata:

Start everything with:

docker compose up -d

Volume Mounts

PathPurpose
./.storageLocal file storage (when STORAGE_DRIVER=local)
pgdataPostgreSQL data persistence

Mount .storage/ as a volume to persist uploaded files across container restarts. If you use an S3-compatible storage driver, this volume is not needed.

Image Size Optimization

The multi-stage build ensures the final image only contains:

  • Node.js 22 Alpine runtime
  • pnpm (from Corepack, for potential runtime needs)
  • The .output/ directory (Nitro server bundle)

Source code, node_modules, build tools, and TypeScript are all discarded in the final stage. The image typically stays under 200 MB.

On this page