ZHZ1024 commited on
Commit
c35e8de
·
verified ·
1 Parent(s): 81f5412

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -4
Dockerfile CHANGED
@@ -7,12 +7,29 @@ WORKDIR /app
7
  # 复制当前目录内容到容器中
8
  COPY . /app
9
 
10
- # 安装依赖
 
 
 
 
 
 
11
  RUN pip install --no-cache-dir -r requirements.txt
12
- RUN python -m playwright install
13
  RUN pip install requests
 
 
 
 
 
 
 
 
 
 
 
 
14
  # 暴露端口
15
  EXPOSE 8000
16
- USER root
17
  # 运行应用
18
- CMD ["sh", "-c", "python -m playwright install && uvicorn api:app --host 0.0.0.0 --port 8000"]
 
7
  # 复制当前目录内容到容器中
8
  COPY . /app
9
 
10
+ # 安装Playwright系统依赖和Python包
11
+ RUN apt-get update && \
12
+ apt-get install -y \
13
+ wget \
14
+ && rm -rf /var/lib/apt/lists/*
15
+
16
+ # 安装Python依赖
17
  RUN pip install --no-cache-dir -r requirements.txt
 
18
  RUN pip install requests
19
+
20
+ # 设置Playwright缓存目录的环境变量
21
+ ENV PLAYWRIGHT_BROWSERS_PATH=/app/playwright-browsers
22
+
23
+ # 安装Playwright和浏览器(使用普通用户权限)
24
+ RUN pip install playwright && \
25
+ playwright install --with-deps
26
+
27
+ # 创建非root用户并切换
28
+ RUN useradd -m myuser && chown -R myuser:myuser /app
29
+ USER myuser
30
+
31
  # 暴露端口
32
  EXPOSE 8000
33
+
34
  # 运行应用
35
+ CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]