recipe-manager/docs/docker-backend.md

1.9 KiB

Backend Dockerfile Guide

Overview

Multi-stage Dockerfile for the Recipe Manager backend API.

Build

docker build -t recipe-manager-backend:latest .

Run

# Simple run
docker run -p 3000:3000 -v $(pwd)/data:/app/data recipe-manager-backend:latest

# With environment variables
docker run \
  -p 3000:3000 \
  -v $(pwd)/data:/app/data \
  -e NODE_ENV=production \
  -e DATABASE_PATH=/app/data/recipes.db \
  recipe-manager-backend:latest

Volume Mounts

Required:

  • /app/data — SQLite database storage (persistent)

Ports

  • 3000 — API server

Environment Variables

Variable Default Description
NODE_ENV production Node environment
DATABASE_PATH /app/data/recipes.db SQLite database path

Image Details

Base: node:22-alpine
Size: ~200MB (optimized with multi-stage build)
Architecture: x86_64, arm64 (via Node.js official images)

Build Process

  1. Builder stage: Installs all dependencies, builds TypeScript
  2. Production stage: Copies only built files, production dependencies
  3. Startup: Runs migrations, then starts Express server

What's Included

  • Built JavaScript (dist/)
  • Production npm dependencies
  • Database schema (src/backend/db/schema.sql)
  • Migration script

What's Excluded (via .dockerignore)

  • Source TypeScript files
  • Tests
  • Frontend code
  • Documentation
  • Development dependencies

Health Check

curl http://localhost:3000/
# Expected: {"success":true,"message":"Recipe Manager API is running","version":"0.1.0"}

Debugging

# View logs
docker logs <container_id>

# Access shell
docker exec -it <container_id> sh

# Check database
docker exec -it <container_id> ls -lh /app/data/

Next Steps

Use with docker-compose.yml for complete stack (backend + frontend + proxy).