2026-01-18 15:58:05 +08:00
|
|
|
|
version: '3.8'
|
|
|
|
|
|
|
|
|
|
|
|
services:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
# PostgreSQL 数据库(使用最新版 17)
|
|
|
|
|
|
postgres:
|
|
|
|
|
|
image: postgres:17-alpine
|
|
|
|
|
|
container_name: life-echo-postgres
|
|
|
|
|
|
ports:
|
|
|
|
|
|
- "5432:5432"
|
|
|
|
|
|
environment:
|
|
|
|
|
|
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
|
|
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
|
|
|
|
POSTGRES_DB: ${POSTGRES_DB:-life_echo}
|
|
|
|
|
|
volumes:
|
|
|
|
|
|
- postgres_data:/var/lib/postgresql/data
|
|
|
|
|
|
restart: always
|
|
|
|
|
|
healthcheck:
|
|
|
|
|
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
|
|
|
|
interval: 10s
|
|
|
|
|
|
timeout: 5s
|
|
|
|
|
|
retries: 5
|
|
|
|
|
|
networks:
|
|
|
|
|
|
- life-echo-network
|
|
|
|
|
|
logging:
|
|
|
|
|
|
driver: "json-file"
|
|
|
|
|
|
options:
|
|
|
|
|
|
max-size: "10m"
|
|
|
|
|
|
max-file: "3"
|
|
|
|
|
|
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# Redis 服务(用于会话存储和 Celery 消息队列)
|
|
|
|
|
|
redis:
|
|
|
|
|
|
image: redis:7-alpine
|
|
|
|
|
|
container_name: life-echo-redis
|
|
|
|
|
|
ports:
|
|
|
|
|
|
- "6379:6379"
|
|
|
|
|
|
volumes:
|
|
|
|
|
|
- redis_data:/data
|
|
|
|
|
|
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
|
|
|
|
|
|
restart: always
|
|
|
|
|
|
healthcheck:
|
|
|
|
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
|
|
|
|
interval: 10s
|
|
|
|
|
|
timeout: 5s
|
|
|
|
|
|
retries: 5
|
|
|
|
|
|
networks:
|
|
|
|
|
|
- life-echo-network
|
|
|
|
|
|
logging:
|
|
|
|
|
|
driver: "json-file"
|
|
|
|
|
|
options:
|
|
|
|
|
|
max-size: "10m"
|
|
|
|
|
|
max-file: "3"
|
|
|
|
|
|
|
|
|
|
|
|
# FastAPI 应用
|
2026-01-18 15:58:05 +08:00
|
|
|
|
api:
|
|
|
|
|
|
build:
|
|
|
|
|
|
context: .
|
|
|
|
|
|
dockerfile: Dockerfile
|
|
|
|
|
|
image: life-echo-api:latest
|
|
|
|
|
|
container_name: life-echo-api-prod
|
|
|
|
|
|
ports:
|
|
|
|
|
|
- "8000:8000"
|
|
|
|
|
|
env_file:
|
2026-01-27 23:07:05 +01:00
|
|
|
|
- .env.production
|
2026-01-21 23:06:47 +01:00
|
|
|
|
environment:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
- DATABASE_URL=postgresql://postgres:postgres@postgres:5432/life_echo
|
2026-01-21 23:06:47 +01:00
|
|
|
|
- REDIS_URL=redis://redis:6379/0
|
2026-01-18 15:58:05 +08:00
|
|
|
|
restart: always
|
2026-01-21 23:06:47 +01:00
|
|
|
|
depends_on:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
postgres:
|
|
|
|
|
|
condition: service_healthy
|
2026-01-21 23:06:47 +01:00
|
|
|
|
redis:
|
|
|
|
|
|
condition: service_healthy
|
2026-01-18 15:58:05 +08:00
|
|
|
|
healthcheck:
|
2026-01-18 17:09:10 +08:00
|
|
|
|
test: ["CMD", "python", "-c", "import http.client; conn = http.client.HTTPConnection('localhost', 8000); conn.request('GET', '/health'); r = conn.getresponse(); exit(0 if r.status == 200 else 1)"]
|
2026-01-18 15:58:05 +08:00
|
|
|
|
interval: 30s
|
|
|
|
|
|
timeout: 10s
|
|
|
|
|
|
retries: 3
|
2026-01-21 23:21:36 +01:00
|
|
|
|
start_period: 15s
|
2026-01-18 15:58:05 +08:00
|
|
|
|
networks:
|
|
|
|
|
|
- life-echo-network
|
2026-01-18 17:09:10 +08:00
|
|
|
|
logging:
|
|
|
|
|
|
driver: "json-file"
|
|
|
|
|
|
options:
|
|
|
|
|
|
max-size: "10m"
|
|
|
|
|
|
max-file: "3"
|
2026-01-21 23:06:47 +01:00
|
|
|
|
|
|
|
|
|
|
# Celery Worker(后台任务处理)
|
|
|
|
|
|
celery-worker:
|
|
|
|
|
|
build:
|
|
|
|
|
|
context: .
|
|
|
|
|
|
dockerfile: Dockerfile
|
|
|
|
|
|
image: life-echo-api:latest
|
|
|
|
|
|
container_name: life-echo-celery-worker
|
|
|
|
|
|
command: celery -A tasks.celery_app worker --loglevel=info --concurrency=4
|
|
|
|
|
|
env_file:
|
2026-01-27 23:07:05 +01:00
|
|
|
|
- .env.production
|
2026-01-21 23:06:47 +01:00
|
|
|
|
environment:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
- DATABASE_URL=postgresql://postgres:postgres@postgres:5432/life_echo
|
2026-01-21 23:06:47 +01:00
|
|
|
|
- REDIS_URL=redis://redis:6379/0
|
|
|
|
|
|
restart: always
|
|
|
|
|
|
depends_on:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
postgres:
|
|
|
|
|
|
condition: service_healthy
|
2026-01-21 23:06:47 +01:00
|
|
|
|
redis:
|
|
|
|
|
|
condition: service_healthy
|
|
|
|
|
|
api:
|
|
|
|
|
|
condition: service_healthy
|
|
|
|
|
|
networks:
|
|
|
|
|
|
- life-echo-network
|
|
|
|
|
|
logging:
|
|
|
|
|
|
driver: "json-file"
|
|
|
|
|
|
options:
|
|
|
|
|
|
max-size: "10m"
|
|
|
|
|
|
max-file: "3"
|
|
|
|
|
|
|
|
|
|
|
|
# Celery Beat(定时任务调度,可选)
|
|
|
|
|
|
# celery-beat:
|
|
|
|
|
|
# build:
|
|
|
|
|
|
# context: .
|
|
|
|
|
|
# dockerfile: Dockerfile
|
|
|
|
|
|
# image: life-echo-api:latest
|
|
|
|
|
|
# container_name: life-echo-celery-beat
|
|
|
|
|
|
# command: celery -A tasks.celery_app beat --loglevel=info
|
|
|
|
|
|
# env_file:
|
2026-01-27 23:07:05 +01:00
|
|
|
|
# - .env.production
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# environment:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
# - DATABASE_URL=postgresql://postgres:postgres@postgres:5432/life_echo
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# - REDIS_URL=redis://redis:6379/0
|
|
|
|
|
|
# restart: always
|
|
|
|
|
|
# depends_on:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
# postgres:
|
|
|
|
|
|
# condition: service_healthy
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# redis:
|
|
|
|
|
|
# condition: service_healthy
|
|
|
|
|
|
# networks:
|
|
|
|
|
|
# - life-echo-network
|
|
|
|
|
|
|
|
|
|
|
|
# Flower(Celery 监控面板,可选)
|
|
|
|
|
|
# flower:
|
|
|
|
|
|
# build:
|
|
|
|
|
|
# context: .
|
|
|
|
|
|
# dockerfile: Dockerfile
|
|
|
|
|
|
# image: life-echo-api:latest
|
|
|
|
|
|
# container_name: life-echo-flower
|
|
|
|
|
|
# command: celery -A tasks.celery_app flower --port=5555
|
|
|
|
|
|
# ports:
|
|
|
|
|
|
# - "5555:5555"
|
|
|
|
|
|
# env_file:
|
2026-01-27 23:07:05 +01:00
|
|
|
|
# - .env.production
|
2026-01-21 23:06:47 +01:00
|
|
|
|
# environment:
|
|
|
|
|
|
# - REDIS_URL=redis://redis:6379/0
|
|
|
|
|
|
# restart: always
|
|
|
|
|
|
# depends_on:
|
|
|
|
|
|
# redis:
|
|
|
|
|
|
# condition: service_healthy
|
|
|
|
|
|
# networks:
|
|
|
|
|
|
# - life-echo-network
|
2026-01-18 15:58:05 +08:00
|
|
|
|
|
|
|
|
|
|
networks:
|
|
|
|
|
|
life-echo-network:
|
|
|
|
|
|
driver: bridge
|
2026-01-21 23:06:47 +01:00
|
|
|
|
|
|
|
|
|
|
volumes:
|
2026-01-21 23:21:36 +01:00
|
|
|
|
postgres_data:
|
|
|
|
|
|
driver: local
|
2026-01-21 23:06:47 +01:00
|
|
|
|
redis_data:
|
|
|
|
|
|
driver: local
|