File size: 904 Bytes
0174493 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 使用官方 Python 镜像作为基础镜像
FROM python:3.9-slim
# 设置工作目录
WORKDIR /code
# 将依赖文件复制到工作目录
COPY ./requirements.txt /code/requirements.txt
# 安装依赖
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# 将应用程序代码复制到工作目录
# 如果您的 main.py 在 app 文件夹内,就这样复制整个 app 文件夹
COPY ./app /code/app
# 暴露应用程序运行的端口 (Hugging Face Spaces 通常使用 7860)
# HF 会自动设置 PORT 环境变量,我们可以在 CMD 中使用它
EXPOSE 7860
# 运行应用程序的命令
# 这会启动 uvicorn 服务器来运行你的 FastAPI 应用 (app.main:app)
# --host 0.0.0.0 使其可以从外部访问
# --port ${PORT:-7860} 使用 HF 提供的 PORT 环境变量,如果未设置则默认为 7860
CMD sh -c "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860}" |