Forrest99 commited on
Commit
2126d90
·
verified ·
1 Parent(s): e6e9cd7

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -1
Dockerfile CHANGED
@@ -1,9 +1,24 @@
 
1
  FROM python:3.9-slim
2
 
 
 
 
 
3
  WORKDIR /app
 
 
 
 
 
 
 
 
4
  COPY requirements.txt .
5
- RUN pip install --no-cache-dir -r requirements.txt
6
 
 
7
  COPY . .
8
 
 
9
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # 基础镜像
2
  FROM python:3.9-slim
3
 
4
+ # 创建专用用户(避免使用root)
5
+ RUN useradd -m -u 1000 appuser
6
+
7
+ # 设置工作目录
8
  WORKDIR /app
9
+
10
+ # 创建缓存目录并赋权
11
+ RUN mkdir -p /app/.cache/huggingface && chown -R appuser:appuser /app
12
+
13
+ # 切换用户(关键权限设置)
14
+ USER appuser
15
+
16
+ # 安装依赖
17
  COPY requirements.txt .
18
+ RUN pip install --user --no-cache-dir -r requirements.txt
19
 
20
+ # 复制应用代码
21
  COPY . .
22
 
23
+ # 启动命令
24
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]