malt666 commited on
Commit
52da221
·
verified ·
1 Parent(s): 256d363

Upload 5 files

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -5
Dockerfile CHANGED
@@ -1,24 +1,46 @@
1
  FROM python:3.11-slim
2
 
3
- # 设置用户为root
4
- USER root
5
-
6
  WORKDIR /app
7
 
 
 
 
 
 
 
 
8
  COPY requirements.txt .
9
- RUN pip install --no-cache-dir -r requirements.txt
10
 
 
 
 
 
 
11
  COPY . .
12
 
13
  # 设置环境变量
14
  ENV HOST=0.0.0.0
15
  ENV PORT=7860
 
 
16
 
17
  # 删除敏感文件
18
  RUN rm -f config.json password.txt
19
 
 
 
 
 
 
 
 
20
  # 暴露端口(Hugging Face默认使用7860端口)
21
  EXPOSE 7860
22
 
 
 
 
 
23
  # 启动命令
24
- CMD ["python", "app.py"]
 
1
  FROM python:3.11-slim
2
 
3
+ # 设置工作目录
 
 
4
  WORKDIR /app
5
 
6
+ # 安装系统依赖
7
+ RUN apt-get update && apt-get install -y \
8
+ build-essential \
9
+ curl \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # 复制依赖文件
13
  COPY requirements.txt .
 
14
 
15
+ # 安装Python依赖
16
+ RUN pip install --no-cache-dir --upgrade pip && \
17
+ pip install --no-cache-dir -r requirements.txt
18
+
19
+ # 复制应用代码
20
  COPY . .
21
 
22
  # 设置环境变量
23
  ENV HOST=0.0.0.0
24
  ENV PORT=7860
25
+ ENV PYTHONUNBUFFERED=1
26
+ ENV DEBIAN_FRONTEND=noninteractive
27
 
28
  # 删除敏感文件
29
  RUN rm -f config.json password.txt
30
 
31
+ # 创建非root用户
32
+ RUN useradd -m -u 1000 user && \
33
+ chown -R user:user /app
34
+
35
+ # 切换到非root用户
36
+ USER user
37
+
38
  # 暴露端口(Hugging Face默认使用7860端口)
39
  EXPOSE 7860
40
 
41
+ # 健康检查
42
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
43
+ CMD curl -f http://localhost:7860/health || exit 1
44
+
45
  # 启动命令
46
+ CMD ["python", "app.py"]