Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +12 -13
Dockerfile
CHANGED
@@ -1,24 +1,23 @@
|
|
1 |
-
# 基础镜像
|
2 |
FROM python:3.9-slim
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
6 |
|
7 |
-
#
|
8 |
-
|
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"]
|