# 使用官方轻量级 Python 镜像 FROM python:3.9-slim # 设置工作目录 WORKDIR /app # 设置环境变量,防止 Python 生成 .pyc 文件,并实时打印日志 ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 # 安装系统依赖 (如果需要) # RUN apt-get update && apt-get install -y gcc # 复制依赖文件 COPY requirements.txt . # 安装 Python 依赖 RUN pip install --no-cache-dir -r requirements.txt # 复制项目代码 COPY app . # 暴露端口 EXPOSE 8000 # 启动命令 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]