Forrest99 commited on
Commit
db0f531
·
verified ·
1 Parent(s): 313b01c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +12 -13
Dockerfile CHANGED
@@ -1,24 +1,23 @@
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"]
 
 
1
  FROM python:3.9-slim
2
 
3
+ # 设置缓存目录路径(统一路径便于管理)
4
+ ENV HF_HOME=/app/.cache/huggingface
5
+ ENV TRANSFORMERS_CACHE=$HF_HOME
6
 
7
+ # 创建专用用户并设置权限
8
+ RUN useradd -m -u 1000 appuser && \
9
+ mkdir -p $HF_HOME && \
10
+ chown -R appuser:appuser /app
 
11
 
12
+ WORKDIR /app
13
  USER appuser
14
 
15
+ # 高效安装依赖
16
  COPY requirements.txt .
17
  RUN pip install --user --no-cache-dir -r requirements.txt
18
 
19
+ # 复制应用代码(排除无关文件)
20
+ COPY app.py ./
21
 
22
+ # Hugging Face Spaces专用端口配置
23
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]