60 lines
2.5 KiB
YAML
60 lines
2.5 KiB
YAML
services:
|
|
|
|
# ── MySQL ────────────────────────────────────────────────────────────────────
|
|
db:
|
|
image: mysql:8.0
|
|
restart: unless-stopped
|
|
env_file: .env
|
|
environment:
|
|
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
|
|
MYSQL_DATABASE: ${MYSQL_DATABASE}
|
|
MYSQL_USER: ${MYSQL_USER}
|
|
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
|
|
volumes:
|
|
- mysql_data:/var/lib/mysql # persistent data
|
|
- ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql:ro # run once on first start
|
|
healthcheck:
|
|
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
start_period: 30s
|
|
networks:
|
|
- backend
|
|
|
|
# ── FastAPI ──────────────────────────────────────────────────────────────────
|
|
api:
|
|
build: ./backend
|
|
restart: unless-stopped
|
|
env_file: .env
|
|
environment:
|
|
DATABASE_URL: mysql+pymysql://${MYSQL_USER}:${MYSQL_PASSWORD}@db/${MYSQL_DATABASE}
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy # wait for MySQL to be ready before starting
|
|
networks:
|
|
- backend
|
|
|
|
# ── Nginx ────────────────────────────────────────────────────────────────────
|
|
nginx:
|
|
image: nginx:alpine
|
|
restart: unless-stopped
|
|
ports:
|
|
- "8056:80"
|
|
volumes:
|
|
- ./nginx/html:/usr/share/nginx/html:ro # static files — edit locally, live immediately
|
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro # nginx config
|
|
depends_on:
|
|
- api
|
|
networks:
|
|
- backend
|
|
|
|
# ── Volumes ───────────────────────────────────────────────────────────────────
|
|
volumes:
|
|
mysql_data: # survives container restarts and rebuilds
|
|
|
|
# ── Networks ──────────────────────────────────────────────────────────────────
|
|
networks:
|
|
backend:
|
|
driver: bridge
|