# 使用官方的 Python 3.9 轻量级镜像 FROM python:3.9-slim # 设置工作目录 WORKDIR /app # 将项目所有文件复制到工作目录 (main.py 和 requirements.txt) COPY . . # 从 requirements.txt 安装所有 Python 依赖 RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # 暴露 FastAPI 默认运行的 8000 端口 EXPOSE 8000 # 容器启动时运行的命令 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]