tingche / Dockerfile
Ethscriptions's picture
Create Dockerfile
8ee51a2 verified
raw
history blame contribute delete
980 Bytes
# Dockerfile
# 1. 使用官方的 Python 3.9 轻量级镜像作为基础
FROM python:3.9-slim
# 2. 在容器内创建一个工作目录 /app
WORKDIR /app
# 3. 将 requirements.txt 复制到工作目录中
# 这样做可以利用Docker的层缓存,如果依赖不变,就不需要重新安装
COPY requirements.txt .
# 4. 安装 requirements.txt 中定义的所有Python依赖
# --no-cache-dir 参数可以减小镜像体积
RUN pip install --no-cache-dir -r requirements.txt
# 5. 将项目中的所有文件(app.py, static/文件夹等)复制到工作目录
COPY . .
# 6. 暴露端口。Hugging Face Spaces 默认使用 7860 端口
EXPOSE 7860
# 7. 容器启动时要执行的命令
# - "app:app": 运行 app.py 文件中的 FastAPI 实例 app
# - "--host 0.0.0.0": 监听所有网络接口,这是容器化应用所必需的
# - "--port 7860": 在Hugging Face指定的端口上运行
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]