- app/main.py: root endpoint + /health that reports DB connectivity - app/db.py: pymysql connection check from MYSQL_* env vars, logged at startup - Dockerfile: python:3.12-slim, port 8720 - docker-compose.yml: mysql:8.2 with healthcheck, app waits for DB ready - requirements.txt: fastapi, uvicorn, pymysql Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
633 B
YAML
30 lines
633 B
YAML
services:
|
|
db:
|
|
image: mysql:8.2
|
|
restart: unless-stopped
|
|
env_file: .env
|
|
volumes:
|
|
- mysql_data:/var/lib/mysql
|
|
- ./db.sql:/docker-entrypoint-initdb.d/01_schema.sql
|
|
healthcheck:
|
|
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--silent"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 10
|
|
start_period: 30s
|
|
|
|
app:
|
|
build: .
|
|
ports:
|
|
- "8720:8720"
|
|
env_file: .env
|
|
environment:
|
|
MYSQL_HOST: db # override localhost → compose service name
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
mysql_data:
|