PythonDockerFastAPIPython
2026-01-15 08:39阅读:28评论:0
docker 部署Python FastAPI项目
FROM python:3.12-slim WORKDIR /app # 安装依赖 COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # COPY app.py . # 暴露端口
1
2
3
4
5
6
7
8
9
10
11
12
FROM python:3.12-slimWORKDIR /app# 安装依赖COPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txt# 复制代码COPY app.py .# 暴露端口EXPOSE 8000# 启动服务CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]