Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +16 -12
Dockerfile
CHANGED
@@ -1,30 +1,34 @@
|
|
1 |
-
# 使用轻量级基础镜像
|
2 |
FROM python:3.10-slim-bookworm
|
3 |
|
4 |
-
#
|
|
|
|
|
|
|
|
|
|
|
5 |
ENV TRANSFORMERS_CACHE=/model-cache \
|
6 |
HF_HOME=/model-cache \
|
7 |
PYTHONUNBUFFERED=1
|
8 |
|
9 |
-
#
|
10 |
RUN apt-get update && \
|
11 |
apt-get install -y --no-install-recommends gcc python3-dev && \
|
12 |
rm -rf /var/lib/apt/lists/*
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
pip install --no-cache-dir -r requirements.txt
|
18 |
|
19 |
-
#
|
20 |
-
RUN useradd -m appuser && chown -R appuser /model-cache
|
21 |
USER appuser
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# 复制应用代码
|
24 |
COPY app.py .
|
25 |
|
26 |
-
# 暴露API端口
|
27 |
EXPOSE 8080
|
28 |
-
|
29 |
-
# 启动命令(生产级WSGI服务器)
|
30 |
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--timeout", "120", "app:app"]
|
|
|
|
|
1 |
FROM python:3.10-slim-bookworm
|
2 |
|
3 |
+
# 第一阶段:以root身份准备环境
|
4 |
+
# 创建缓存目录并设置权限
|
5 |
+
RUN mkdir -p /model-cache && \
|
6 |
+
chmod 777 /model-cache
|
7 |
+
|
8 |
+
# 设置环境变量
|
9 |
ENV TRANSFORMERS_CACHE=/model-cache \
|
10 |
HF_HOME=/model-cache \
|
11 |
PYTHONUNBUFFERED=1
|
12 |
|
13 |
+
# 安装系统依赖
|
14 |
RUN apt-get update && \
|
15 |
apt-get install -y --no-install-recommends gcc python3-dev && \
|
16 |
rm -rf /var/lib/apt/lists/*
|
17 |
|
18 |
+
# 创建应用用户(避免使用useradd权限问题)
|
19 |
+
RUN adduser --disabled-password --gecos "" appuser && \
|
20 |
+
chown -R appuser:appuser /model-cache
|
|
|
21 |
|
22 |
+
# 切换用户
|
|
|
23 |
USER appuser
|
24 |
+
WORKDIR /app
|
25 |
+
|
26 |
+
# 安装Python依赖
|
27 |
+
COPY requirements.txt .
|
28 |
+
RUN pip install --user --no-cache-dir -r requirements.txt
|
29 |
|
30 |
# 复制应用代码
|
31 |
COPY app.py .
|
32 |
|
|
|
33 |
EXPOSE 8080
|
|
|
|
|
34 |
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--timeout", "120", "app:app"]
|