# 使用Python 3.9官方镜像作为基础镜像 FROM python:3.9-slim # 设置工作目录 WORKDIR /app # 安装系统依赖 RUN apt-get update && apt-get install -y \ gcc \ g++ \ libjpeg-dev \ libpng-dev \ libfreetype6-dev \ && rm -rf /var/lib/apt/lists/* # 复制 requirements.txt 文件到容器中 COPY requirements.txt . # 安装 Python 依赖 RUN pip install --no-cache-dir -r requirements.txt # 复制你的应用代码到容器中 COPY . . # 暴露 Flask 应用运行的端口,这里使用 Hugging Face 默认的 7860 EXPOSE 7860 # 启动 Gunicorn 服务器来运行 Flask 应用 # Gunicorn 比 Flask 自带的开发服务器更适合生产环境 # 绑定到 0.0.0.0 确保它能被外部访问 CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "4", "app:app"]