Forrest99 commited on
Commit
1e8a35b
·
verified ·
1 Parent(s): e95b6e9

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +8 -15
Dockerfile CHANGED
@@ -1,17 +1,15 @@
1
- # 使用Python官方镜像
2
  FROM python:3.10-slim
3
 
4
- # 设置环境变量(正确语法)
5
- ENV HF_HOME=/model-cache \
6
- PYTHONUNBUFFERED=1 \
7
- PORT=7860
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
- # 创建非root用户
15
  RUN useradd -m appuser && \
16
  mkdir -p /model-cache && \
17
  chown -R appuser:appuser /model-cache
@@ -20,19 +18,14 @@ RUN useradd -m appuser && \
20
  USER appuser
21
  WORKDIR /app
22
 
23
- # 复制依赖文件
24
  COPY requirements.txt .
25
-
26
- # 安装依赖并预下载模型
27
  RUN pip install --no-cache-dir --upgrade pip && \
28
- pip install --no-cache-dir -r requirements.txt && \
29
- python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('flax-sentence-embeddings/st-codesearch-distilroberta-base')"
30
 
31
  # 复制应用代码
32
  COPY app.py .
33
 
34
- # 暴露端口
35
  EXPOSE 7860
36
-
37
- # 启动命令
38
- CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "600", "app:app"]
 
 
1
  FROM python:3.10-slim
2
 
3
+ # 设置全局环境变量
4
+ ENV PYTHONUNBUFFERED=1 \
5
+ PATH="/home/appuser/.local/bin:${PATH}"
 
6
 
7
  # 安装系统依赖
8
  RUN apt-get update && \
9
  apt-get install -y --no-install-recommends gcc python3-dev && \
10
  rm -rf /var/lib/apt/lists/*
11
 
12
+ # 创建应用用户
13
  RUN useradd -m appuser && \
14
  mkdir -p /model-cache && \
15
  chown -R appuser:appuser /model-cache
 
18
  USER appuser
19
  WORKDIR /app
20
 
21
+ # 安装Python依赖(全局安装)
22
  COPY requirements.txt .
 
 
23
  RUN pip install --no-cache-dir --upgrade pip && \
24
+ pip install --no-cache-dir gunicorn==21.2.0 && \ # 显式安装gunicorn
25
+ pip install --no-cache-dir -r requirements.txt
26
 
27
  # 复制应用代码
28
  COPY app.py .
29
 
 
30
  EXPOSE 7860
31
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]