Dockerfile.prod
1.01 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# ============ Stage 1: Builder ============
FROM python:3.12-slim AS builder
WORKDIR /build
# 安装编译依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# 安装 Python 依赖到指定目录(便于后续拷贝)
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# ============ Stage 2: Runtime ============
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
# 从 builder 拷贝已安装的 Python 包
COPY --from=builder /install /usr/local
# 拷贝项目文件
COPY app/ ./app/
COPY config/ ./config/
COPY skills/ ./skills/
COPY sitecustomize.py ./
# 创建非 root 用户并切换
RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser \
&& chown -R appuser:appuser /app
USER appuser
EXPOSE 8000
# 生产模式:多进程,无热重载
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]