Forrest99 commited on
Commit
73e30a3
·
verified ·
1 Parent(s): 2cb159c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -12
Dockerfile CHANGED
@@ -1,21 +1,31 @@
1
  FROM python:3.10-slim
2
 
3
- # 设置缓存路径(与网页配置一致)
4
  ENV TRANSFORMERS_CACHE=/model-cache \
5
- PYTHONUNBUFFERED=1
6
-
7
- # 创建缓存目录(所有用户可写)
8
- RUN mkdir -p /model-cache && chmod 777 /model-cache
9
 
10
  # 安装系统依赖
11
- RUN apt-get update && apt-get install -y --no-install-recommends gcc python3-dev
 
 
 
 
 
 
 
12
 
13
- # 复制代码
 
14
  WORKDIR /app
15
- COPY . .
16
 
17
- # 安装Python依赖(全局安装)
18
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
19
 
20
- # 直接使用 root 用户运行(避免权限问题)
21
- CMD ["gunicorn", "--bind", "0.0.0.0:8080", "app:app"]
 
1
  FROM python:3.10-slim
2
 
3
+ # 设置环境变量
4
  ENV TRANSFORMERS_CACHE=/model-cache \
5
+ PYTHONUNBUFFERED=1 \
6
+ PATH="/home/appuser/.local/bin:${PATH}"
 
 
7
 
8
  # 安装系统依赖
9
+ RUN apt-get update && \
10
+ apt-get install -y --no-install-recommends gcc python3-dev && \
11
+ rm -rf /var/lib/apt/lists/*
12
+
13
+ # 创建用户和缓存目录
14
+ RUN adduser --disabled-password --gecos "" appuser && \
15
+ mkdir -p /model-cache && \
16
+ chown -R appuser:appuser /model-cache
17
 
18
+ # 切换用户
19
+ USER appuser
20
  WORKDIR /app
 
21
 
22
+ # 安装Python依赖
23
+ COPY requirements.txt .
24
+ RUN pip install --no-cache-dir --upgrade pip && \
25
+ pip install --no-cache-dir -r requirements.txt
26
+
27
+ # 复制应用代码
28
+ COPY app.py .
29
 
30
+ EXPOSE 8080
31
+ CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--timeout", "120", "app:app"]