更新 Dockerfile_python_fastapi

This commit is contained in:
2025-03-29 12:59:06 +00:00
parent 88269b102e
commit cefc0cffda

View File

@@ -1,30 +1,30 @@
FROM python:3.12-slim-bookworm FROM python:3.12-slim-bookworm
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# 设置工作目录 # 设置工作目录
WORKDIR /app WORKDIR /app
# 设置环境变量 # 设置环境变量
ENV PYTHONUNBUFFERED=1 \ ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 PYTHONDONTWRITEBYTECODE=1
# 安装系统依赖 # 安装系统依赖
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
build-essential \ build-essential \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# 复制依赖文件 # 复制依赖文件
COPY pyproject.toml . COPY pyproject.toml .
# 安装项目依赖 # 安装项目依赖
RUN uv pip compile pyproject.toml -o requirements.txt && pip install --no-cache-dir -r requirements.txt RUN uv pip compile pyproject.toml -o requirements.txt && pip install --no-cache-dir -r requirements.txt
# 复制项目文件 # 复制项目文件
COPY . . COPY . .
# 暴露端口 # 暴露端口
EXPOSE 8000 EXPOSE 8000
# 启动命令 # 启动命令
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000","--workers", "8","--timeout-keep-alive", "30"] CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000","--workers", "8","--timeout-keep-alive", "30"]