leonsimon23 commited on
Commit
4df93be
·
verified ·
1 Parent(s): 0612b78

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -7
Dockerfile CHANGED
@@ -1,3 +1,5 @@
 
 
1
  # 1. 使用一个官方的、轻量级的Python 3.10镜像作为基础
2
  FROM python:3.10-slim
3
 
@@ -5,20 +7,24 @@ FROM python:3.10-slim
5
  WORKDIR /app
6
 
7
  # 3. 复制依赖文件到工作目录
8
- # 这一步单独做可以利用Docker的缓存机制,如果requirements.txt没变,则不会重新安装
9
  COPY requirements.txt requirements.txt
10
 
11
  # 4. 安装所有依赖项
12
  # --no-cache-dir 选项可以减小最终镜像的大小
13
- RUN pip install --no-cache-dir -r requirements.txt
 
14
 
15
  # 5. 将项目中的所有文件复制到工作目录
16
- # 这包括 app.py 和 static 文件夹
17
  COPY . .
18
 
19
- # 6. 向Docker声明容器将在哪个端口上监听连接
 
 
 
 
 
20
  EXPOSE 8080
21
 
22
- # 7. 定义容器启动时要执行的命令
23
- # 使用gunicorn作为生产级WSGI服务器来运行Flask应用
24
- CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--workers", "1", "app:app"]
 
1
+ # Dockerfile
2
+
3
  # 1. 使用一个官方的、轻量级的Python 3.10镜像作为基础
4
  FROM python:3.10-slim
5
 
 
7
  WORKDIR /app
8
 
9
  # 3. 复制依赖文件到工作目录
 
10
  COPY requirements.txt requirements.txt
11
 
12
  # 4. 安装所有依赖项
13
  # --no-cache-dir 选项可以减小最终镜像的大小
14
+ # --default-timeout=100 增加超时时间,防止网络慢导致安装失败
15
+ RUN pip install --no-cache-dir -r requirements.txt --default-timeout=100
16
 
17
  # 5. 将项目中的所有文件复制到工作目录
 
18
  COPY . .
19
 
20
+ # 6. 设置健康检查,告诉Hugging Face如何确认应用是否正常运行
21
+ # 它会尝试访问应用的根路径,如果30秒内没有响应,则认为失败
22
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
23
+ CMD curl -f http://localhost:8080/ || exit 1
24
+
25
+ # 7. 向Docker声明容器将在哪个端口上监听连接
26
  EXPOSE 8080
27
 
28
+ # 8. 定义容器启动时要执行的命令
29
+ # 使用gunicorn作为生产级WSGI服务器,增加 --timeout 避免请求处理时间过长被中断
30
+ CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--workers", "1", "--timeout", "120", "app:app"]