Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +22 -12
Dockerfile
CHANGED
@@ -1,21 +1,31 @@
|
|
1 |
FROM python:3.10-slim
|
2 |
|
3 |
-
#
|
4 |
ENV TRANSFORMERS_CACHE=/model-cache \
|
5 |
-
PYTHONUNBUFFERED=1
|
6 |
-
|
7 |
-
# 创建缓存目录(所有用户可写)
|
8 |
-
RUN mkdir -p /model-cache && chmod 777 /model-cache
|
9 |
|
10 |
# 安装系统依赖
|
11 |
-
RUN apt-get update &&
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
|
|
14 |
WORKDIR /app
|
15 |
-
COPY . .
|
16 |
|
17 |
-
# 安装Python
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "app:app"]
|
|
|
1 |
FROM python:3.10-slim
|
2 |
|
3 |
+
# 设置环境变量
|
4 |
ENV TRANSFORMERS_CACHE=/model-cache \
|
5 |
+
PYTHONUNBUFFERED=1 \
|
6 |
+
PATH="/home/appuser/.local/bin:${PATH}"
|
|
|
|
|
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/*
|
12 |
+
|
13 |
+
# 创建用户和缓存目录
|
14 |
+
RUN adduser --disabled-password --gecos "" appuser && \
|
15 |
+
mkdir -p /model-cache && \
|
16 |
+
chown -R appuser:appuser /model-cache
|
17 |
|
18 |
+
# 切换用户
|
19 |
+
USER appuser
|
20 |
WORKDIR /app
|
|
|
21 |
|
22 |
+
# 安装Python依赖
|
23 |
+
COPY requirements.txt .
|
24 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
25 |
+
pip install --no-cache-dir -r requirements.txt
|
26 |
+
|
27 |
+
# 复制应用代码
|
28 |
+
COPY app.py .
|
29 |
|
30 |
+
EXPOSE 8080
|
31 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--timeout", "120", "app:app"]
|