READ-ONLY PACKAGE PREVIEW

docker-project-foundations/assets/compose-dev.yaml

Version 3e1cbd179989 · Apache-2.0. This preview displays packaged text and does not execute code. Treat the contents as untrusted instructions.

← Return to resource and package checksum

# Development-oriented compose.yaml
# Demonstrates Dockerized dependencies, health checks, bind mounts, and named volumes.
# The Postgres password fallback is for development-only one-command startup.
# Set POSTGRES_PASSWORD in .env to override it for local development.

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      target: dev  # Use the dev stage of a multi-stage Dockerfile
    ports:
      - "127.0.0.1:3000:3000"  # Use 0.0.0.0 only when other devices need access
    environment:
      - DATABASE_URL=postgres://appuser:${POSTGRES_PASSWORD:-apppass}@db:5432/appdb
      - REDIS_URL=redis://cache:6379
      - NODE_ENV=development
    volumes:
      - ./src:/app/src        # Bind mount for live reload
      - /app/node_modules     # Anonymous volume to avoid overwriting installed deps
    depends_on:
      db:
        condition: service_healthy
      cache:
        condition: service_healthy

  db:
    image: postgres:17
    environment:
      - POSTGRES_USER=appuser
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-apppass}
      - POSTGRES_DB=appdb
    ports:
      - "127.0.0.1:5432:5432"  # Keep the development database local
    volumes:
      - db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U appuser -d appdb"]
      interval: 5s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  cache:
    image: redis:7
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 5
    restart: unless-stopped

volumes:
  db-data: