Skip to content

Docker Build Guide

This monorepo uses a unified Dockerfile that can build any app using Turbo's pruning feature.

Quick Start

bash
# Start sample-app
docker-compose up -d sample-app

# Start all apps
docker-compose up -d

# View logs
docker-compose logs -f sample-app

# Stop all services
docker-compose down

Using Docker Build Directly

bash
# Build with default settings (sample-app, Node 22)
docker build -t sample-app .

# Build a different app
docker build --build-arg APP_NAME=api -t api .

# Custom Node version and start command
docker build \
  --build-arg APP_NAME=api \
  --build-arg NODE_VERSION=20 \
  --build-arg START_COMMAND="node dist/main.js" \
  -t api .

Using the Helper Script

bash
# Build sample-app with Node 22 (default)
./docker-build.sh sample-app

# Build api with Node 20
./docker-build.sh api 20

Build Arguments

  • APP_NAME (default: sample-app) - The app to build from apps/ directory
  • NODE_VERSION (default: 22) - Node.js version to use
  • START_COMMAND (default: "node dist/index.js") - Command to start the app

Adding a New App to Docker Compose

Edit docker-compose.yml and add a new service:

yaml
your-app:
    build:
        context: .
        dockerfile: Dockerfile
        args:
            APP_NAME: your-app
            NODE_VERSION: 22
            START_COMMAND: 'node dist/main.js'
    image: your-app:latest
    container_name: your-app
    ports:
        - '4000:4000'
    environment:
        - NODE_ENV=production
    restart: unless-stopped

How It Works

  1. Prune Stage: Uses turbo prune to extract only the dependencies needed for your app
  2. Install Stage: Installs dependencies based on the pruned lockfile
  3. Build Stage: Copies source code and builds the app using Turbo
  4. Runner Stage: Creates a minimal Alpine-based production image with only the built artifacts

This approach ensures:

  • ✅ Fast builds with layer caching
  • ✅ Small production images (only necessary dependencies)
  • ✅ Consistent builds across all apps
  • ✅ Proper handling of monorepo workspace dependencies