Add FastAPI hello-world structure with Docker and DB health check
- 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>
This commit is contained in:
29
docker-compose.yml
Normal file
29
docker-compose.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
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:
|
||||
Reference in New Issue
Block a user