Kexin-251202 commited on
Commit
0b6bb7c
·
verified ·
1 Parent(s): d2f1e91

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -23
Dockerfile CHANGED
@@ -1,24 +1,23 @@
1
- # 1. 使用官方 Python 3.9 镜像
2
- FROM python:3.9
3
-
4
- # 2. 设置工作目录
5
- WORKDIR /code
6
-
7
- # 3. 安装 OpenCV 需要的系统依赖 (必须要这一步,否则 cv2 会报错)
8
- RUN apt-get update && apt-get install -y libgl1-mesa-glx
9
-
10
- # 4. 复制依赖文件并安装 Python 库
11
- COPY ./requirements.txt /code/requirements.txt
12
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
13
-
14
- # 5. 复制所有代码 (main.py 和 static 文件) 到容器
15
- COPY . /code
16
-
17
- # 6. 【重要】解决 Hugging Face 的权限问题
18
- # HF 运行在非 root 用户下,我们需要把目录权限设为 777
19
- # 这样程序才能自动创建和 focus_guard.db 数据库文件
20
- RUN chmod 777 /code
21
-
22
- # 7. 启动命令
23
- # 注意:Hugging Face 强制要求端口为 7860
24
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # 1. 使用官方 Python 3.9 镜像
2
+ FROM python:3.9
3
+
4
+ # 2. 设置工作目录
5
+ WORKDIR /code
6
+
7
+ # 3. 安装 OpenCV 需要的系统依赖
8
+ RUN apt-get update && apt-get install -y libgl1-mesa-glx
9
+
10
+ # 4. 复制 requirements.txt 并安装依赖 (利用缓存)
11
+ COPY requirements.txt /code/requirements.txt
12
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
13
+
14
+ # 5. 分步复制文件 (这样如果出错,你知道是哪个文件缺了)
15
+ COPY main.py /code/main.py
16
+ COPY static /code/static
17
+
18
+ # 6. 设置权限 (关键修复)
19
+ # 给所有文件赋予读执行权限,防止 HF 报 Permission denied
20
+ RUN chmod -R 777 /code
21
+
22
+ # 7. 启动命令
 
23
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]