File size: 827 Bytes
3d4d7ca
 
 
 
 
 
 
 
 
c35e8de
 
 
 
 
 
 
3d4d7ca
 
c35e8de
 
 
 
 
 
 
 
 
 
 
 
3d4d7ca
 
c35e8de
3d4d7ca
c35e8de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 使用官方Python镜像作为基础镜像
FROM python:3.10-slim

# 设置工作目录
WORKDIR /app

# 复制当前目录内容到容器中
COPY . /app

# 安装Playwright系统依赖和Python包
RUN apt-get update && \
    apt-get install -y \
    wget \
    && rm -rf /var/lib/apt/lists/*

# 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install requests

# 设置Playwright缓存目录的环境变量
ENV PLAYWRIGHT_BROWSERS_PATH=/app/playwright-browsers

# 安装Playwright和浏览器(使用普通用户权限)
RUN pip install playwright && \
    playwright install --with-deps

# 创建非root用户并切换
RUN useradd -m myuser && chown -R myuser:myuser /app
USER myuser

# 暴露端口
EXPOSE 8000

# 运行应用
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]