Ethscriptions commited on
Commit
8ee51a2
·
verified ·
1 Parent(s): b7852d8

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +27 -0
Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dockerfile
2
+
3
+ # 1. 使用官方的 Python 3.9 轻量级镜像作为基础
4
+ FROM python:3.9-slim
5
+
6
+ # 2. 在容器内创建一个工作目录 /app
7
+ WORKDIR /app
8
+
9
+ # 3. 将 requirements.txt 复制到工作目录中
10
+ # 这样做可以利用Docker的层缓存,如果依赖不变,就不需要重新安装
11
+ COPY requirements.txt .
12
+
13
+ # 4. 安装 requirements.txt 中定义的所有Python依赖
14
+ # --no-cache-dir 参数可以减小镜像体积
15
+ RUN pip install --no-cache-dir -r requirements.txt
16
+
17
+ # 5. 将项目中的所有文件(app.py, static/文件夹等)复制到工作目录
18
+ COPY . .
19
+
20
+ # 6. 暴露端口。Hugging Face Spaces 默认使用 7860 端口
21
+ EXPOSE 7860
22
+
23
+ # 7. 容器启动时要执行的命令
24
+ # - "app:app": 运行 app.py 文件中的 FastAPI 实例 app
25
+ # - "--host 0.0.0.0": 监听所有网络接口,这是容器化应用所必需的
26
+ # - "--port 7860": 在Hugging Face指定的端口上运行
27
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]