Forrest99 commited on
Commit
a324382
·
verified ·
1 Parent(s): 48ea984

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -5
Dockerfile CHANGED
@@ -1,10 +1,11 @@
1
  FROM python:3.9-slim
2
 
3
- # 修复缓存目录权限
4
  RUN mkdir -p /app/.cache/huggingface && \
5
- chmod 777 -R /app
 
6
 
7
- # 安装系统依赖(必需)
8
  RUN apt-get update && \
9
  apt-get install -y --no-install-recommends gcc python3-dev && \
10
  rm -rf /var/lib/apt/lists/*
@@ -14,8 +15,15 @@ COPY requirements.txt .
14
  RUN pip install --upgrade pip && \
15
  pip install --no-cache-dir -r requirements.txt
16
 
 
 
 
17
  # 复制代码
18
- COPY app.py .
 
 
 
 
 
19
 
20
- # 启动命令
21
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.9-slim
2
 
3
+ # 创建缓存目录并提前设置权限
4
  RUN mkdir -p /app/.cache/huggingface && \
5
+ chown -R 1000:1000 /app && \
6
+ chmod -R 755 /app
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/*
 
15
  RUN pip install --upgrade pip && \
16
  pip install --no-cache-dir -r requirements.txt
17
 
18
+ # 切换非root用户
19
+ USER 1000
20
+
21
  # 复制代码
22
+ COPY --chown=1000:1000 app.py .
23
+
24
+ # 环境变量
25
+ ENV HF_HOME=/app/.cache/huggingface \
26
+ TRANSFORMERS_CACHE=/app/.cache/huggingface \
27
+ HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface
28
 
 
29
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]