Files
2026-09-21 17:39:16 +08:00

29 lines
929 B
Docker

# ============================================
# 沃林学生管理系统 (Docker)
# FastAPI + SQLAlchemy + PyMySQL -> MySQL 8
# ============================================
FROM python:3.11-slim
# 运行环境:不生成 .pyc、日志实时输出、pip 不缓存
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
WORKDIR /app
# 1) 先装依赖(利用层缓存,改代码不必重装)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt \
-i https://pypi.tuna.tsinghua.edu.cn/simple
# 2) 拷贝应用代码
COPY . .
# 3) static 为空目录时 COPY 不会生成,手动补上(main.py 挂载时需要)
RUN mkdir -p static
EXPOSE 8001
# 4) 启动流程:建表 -> 灌种子数据(seed_data 有幂等检查,可重复执行) -> 启动服务
CMD ["sh", "-c", "python -c 'from database import init_db; init_db()' && python seed_data.py && exec python main.py"]