File size: 785 Bytes
eb86367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
# ===================================================================
# Dockerfile
# ===================================================================

# 使用官方的 Python 3.9 轻量级镜像
FROM python:3.9-slim

# 设置工作目录
WORKDIR /app

# 将项目所有文件复制到工作目录
# 我们会上传 main.py 和 requirements.txt
COPY . .

# 从 requirements.txt 安装所有 Python 依赖
# --no-cache-dir 选项可以减小镜像体积
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# 暴露 FastAPI 默认运行的 8000 端口
EXPOSE 8000

# 容器启动时运行的命令
# 启动 uvicorn 服务器,监听所有网络接口的 8000 端口
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]