Forrest99 commited on
Commit
45f0945
·
verified ·
1 Parent(s): 5f5f68e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -25
Dockerfile CHANGED
@@ -1,35 +1,30 @@
1
- # 使用官方Python基础镜像
2
- FROM python:3.9-slim as builder
3
 
4
- # 第一阶段:以root身份安装系统依赖
5
- RUN apt-get update && \
6
- apt-get install -y --no-install-recommends \
7
- gcc \
8
- python3-dev \
9
- && rm -rf /var/lib/apt/lists/*
10
 
11
- # 创建应用用户和目录
12
- RUN useradd -m appuser && \
13
- mkdir -p /app/model-cache && \
14
- chown -R appuser:appuser /app
15
 
16
- # 设置环境变量
17
- ENV TRANSFORMERS_CACHE=/app/model-cache \
18
- HF_HOME=/app/model-cache
 
19
 
20
- # 切换到应用用户
 
21
  USER appuser
22
- WORKDIR /app
23
-
24
- # 安装Python依赖
25
- COPY requirements.txt .
26
- RUN pip install --user --no-cache-dir -r requirements.txt
27
 
28
  # 复制应用代码
29
  COPY app.py .
30
 
31
- # 设置PATH环境变量
32
- ENV PATH="/home/appuser/.local/bin:${PATH}"
33
 
34
- EXPOSE 5000
35
- CMD ["python", "app.py"]
 
1
+ # 使用轻量级基础镜像
2
+ FROM python:3.10-slim-bookworm
3
 
4
+ # 设置容器级环境变量
5
+ ENV TRANSFORMERS_CACHE=/model-cache \
6
+ HF_HOME=/model-cache \
7
+ PYTHONUNBUFFERED=1
 
 
8
 
9
+ # 安装必需的系统组件(保持root权限)
10
+ RUN apt-get update && \
11
+ apt-get install -y --no-install-recommends gcc python3-dev && \
12
+ rm -rf /var/lib/apt/lists/*
13
 
14
+ # 安装Python依赖(自动清理缓存)
15
+ COPY requirements.txt .
16
+ RUN pip install --upgrade pip && \
17
+ pip install --no-cache-dir -r requirements.txt
18
 
19
+ # 切换到非root用户
20
+ RUN useradd -m appuser && chown -R appuser /model-cache
21
  USER appuser
 
 
 
 
 
22
 
23
  # 复制应用代码
24
  COPY app.py .
25
 
26
+ # 暴露API端口
27
+ EXPOSE 8080
28
 
29
+ # 启动命令(生产级WSGI服务器)
30
+ CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--timeout", "120", "app:app"]