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 the Bun runtime — no build tools, no source code, no node_modules.
Dockerfile Overview
The Dockerfile uses four stages:
base → Bun Alpine
deps → Install dependencies (cached layer)
build → Full production build
runner → Copy .output/ onlyEach stage prints its disk size with du -sh /app to help track layer bloat during development.
Stage 1: Base
FROM oven/bun:alpine AS base
WORKDIR /appUses the official Bun Alpine image as the base.
Stage 2: Dependencies
FROM base AS deps
COPY package.json bun.lock ./
COPY packages/ packages/
COPY tooling/ tooling/
COPY content/ content/
RUN bun install --frozen-lockfile --ignore-scriptsInstalls all workspace dependencies. This layer is cached as long as bun.lock does not change.
Stage 3: Build
FROM deps AS build
COPY . .
RUN bun run postinstall
RUN NODE_ENV=production bun run buildRuns postinstall scripts and the full Vite production build. The output goes to .output/.
Stage 4: Runner
FROM oven/bun:alpine AS runner
COPY --from=build /app/.output .output
ENV HOST=0.0.0.0
ENV PORT=3001
EXPOSE 3001
CMD ["bun", ".output/server/index.mjs"]Starts fresh from the Bun Alpine 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 raypxAlways 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 -dVolume Mounts
| Path | Purpose |
|---|---|
./.storage | Local file storage (when STORAGE_DRIVER=local) |
pgdata | PostgreSQL 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:
- Bun Alpine runtime
- The
.output/directory (Nitro server bundle)
Source code, node_modules, build tools, and TypeScript are all discarded in the final stage.