Files
ballistic-builder-spring/docker/docker-compose.yaml

63 lines
2.0 KiB
YAML
Raw Normal View History

2025-12-02 17:18:26 -05:00
version: '3.8'
services:
# --- 1. Spring API Service (Backend) ---
spring-api:
build:
context: ./backend # Path to your Spring project's root folder
dockerfile: Dockerfile # Assumes you have a Dockerfile in ./backend
container_name: spring-api
ports:
- "8080:8080" # Map host port 8080 to container port 8080
environment:
# These environment variables link the API to the database service defined below
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/mydatabase
- SPRING_DATASOURCE_USERNAME=myuser
- SPRING_DATASOURCE_PASSWORD=mypassword
depends_on:
- db
networks:
- app-network
# --- 2. Next.js App Service (Frontend) ---
nextjs-app:
build:
context: ./frontend # Path to your Next.js project's root folder
dockerfile: Dockerfile # Assumes you have a Dockerfile in ./frontend
container_name: nextjs-app
ports:
- "3000:3000" # Map host port 3000 to container port 3000
environment:
# This variable is crucial: Next.js needs the URL for the Spring API
# Use the Docker internal service name 'spring-api' and its port 8080
- NEXT_PUBLIC_API_URL=http://spring-api:8080
# For local testing, you might need the host IP for Next.js to call back
# - NEXT_PUBLIC_API_URL_LOCAL=http://localhost:8080
depends_on:
- spring-api
networks:
- app-network
# --- 3. PostgreSQL Database Service (Example Dependency) ---
db:
image: postgres:15-alpine # Lightweight and stable PostgreSQL image
container_name: postgres-db
environment:
- POSTGRES_DB=mydatabase
- POSTGRES_USER=myuser
- POSTGRES_PASSWORD=mypassword
volumes:
- postgres_data:/var/lib/postgresql/data # Persist the database data
ports:
- "5432:5432" # Optional: Map DB port for external access (e.g., DBeaver)
networks:
- app-network
# --- Docker Volume for Persistent Data ---
volumes:
postgres_data:
# --- Docker Network for Inter-Container Communication ---
networks:
app-network:
driver: bridge