-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.serving
More file actions
42 lines (28 loc) · 1.18 KB
/
Copy pathDockerfile.serving
File metadata and controls
42 lines (28 loc) · 1.18 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
42
# ========== Stage 1: 安装依赖 ==========
FROM python:3.11-slim AS builder
WORKDIR /build
# 沿用 .bak 的清华源
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# # 沿用清华源(改用 HTTP 避免 Docker 内 SSL 问题)
# RUN pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/ \
# && pip config set global.trusted-host mirrors.aliyun.com
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# ========== Stage 2: 运行时 ==========
FROM python:3.11-slim
WORKDIR /app
# 创建非 root 用户
RUN groupadd -r appuser && useradd -r -g appuser -d /app appuser
# 仅拷贝已安装的依赖(不含 pip/cache 等构建工具)
COPY --from=builder /install /usr/local
# 拷贝源码
COPY serving/ ./serving/
COPY shared/ ./shared/
# 设置权限
RUN chown -R appuser:appuser /app
USER appuser
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8001/health')" || exit 1
EXPOSE 8001
CMD ["uvicorn", "serving.app:app", "--host", "0.0.0.0", "--port", "8001", "--no-access-log"]