Commit
·
9b0dc4d
1
Parent(s):
4abb273
Switch to python:3.11-slim base image for better compatibility
Browse files- Replace zenika/alpine-chrome with standard Python image
- Install all required system dependencies for Playwright
- Install Playwright browsers during build
- Create non-root user for security
- Should resolve all import and compatibility issues
- Dockerfile +36 -15
Dockerfile
CHANGED
@@ -1,30 +1,51 @@
|
|
1 |
-
FROM
|
2 |
-
|
3 |
-
# Switch to root user to install packages
|
4 |
-
USER root
|
5 |
|
6 |
WORKDIR /app
|
7 |
|
8 |
-
# Install
|
9 |
-
RUN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Copy requirements first for better caching
|
12 |
COPY requirements.txt .
|
13 |
-
RUN
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
|
18 |
# Copy your code
|
19 |
COPY . .
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
|
24 |
-
# FastAPI and Uvicorn are already installed via requirements.txt
|
25 |
-
# Playwright browsers are already available in the base image
|
26 |
|
27 |
EXPOSE 7860
|
28 |
|
29 |
# Run the FastAPI application
|
30 |
-
CMD ["
|
|
|
1 |
+
FROM python:3.11-slim
|
|
|
|
|
|
|
2 |
|
3 |
WORKDIR /app
|
4 |
|
5 |
+
# Install system dependencies for Playwright
|
6 |
+
RUN apt-get update && apt-get install -y \
|
7 |
+
wget \
|
8 |
+
gnupg \
|
9 |
+
ca-certificates \
|
10 |
+
fonts-liberation \
|
11 |
+
libasound2 \
|
12 |
+
libatk-bridge2.0-0 \
|
13 |
+
libatk1.0-0 \
|
14 |
+
libatspi2.0-0 \
|
15 |
+
libcups2 \
|
16 |
+
libdbus-1-3 \
|
17 |
+
libdrm2 \
|
18 |
+
libgtk-3-0 \
|
19 |
+
libnspr4 \
|
20 |
+
libnss3 \
|
21 |
+
libwayland-client0 \
|
22 |
+
libx11-6 \
|
23 |
+
libx11-xcb1 \
|
24 |
+
libxcb1 \
|
25 |
+
libxcomposite1 \
|
26 |
+
libxdamage1 \
|
27 |
+
libxext6 \
|
28 |
+
libxfixes3 \
|
29 |
+
libxrandr2 \
|
30 |
+
libxss1 \
|
31 |
+
libxtst6 \
|
32 |
+
&& rm -rf /var/lib/apt/lists/*
|
33 |
|
34 |
# Copy requirements first for better caching
|
35 |
COPY requirements.txt .
|
36 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
37 |
|
38 |
+
# Install Playwright browsers
|
39 |
+
RUN python -m playwright install chromium
|
40 |
|
41 |
# Copy your code
|
42 |
COPY . .
|
43 |
|
44 |
+
# Create a non-root user for security
|
45 |
+
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
|
46 |
+
USER appuser
|
|
|
|
|
47 |
|
48 |
EXPOSE 7860
|
49 |
|
50 |
# Run the FastAPI application
|
51 |
+
CMD ["python", "-m", "uvicorn", "scrape:app", "--host", "0.0.0.0", "--port", "7860"]
|