Dockerfile aktualisiert
This commit is contained in:
80
Dockerfile
80
Dockerfile
@@ -1,54 +1,64 @@
|
|||||||
# Basis-Image
|
# 1. Basis-Image: Ein schlankes Debian-basiertes Python 3.8
|
||||||
FROM python:3.8-slim
|
FROM python:3.8-slim
|
||||||
|
|
||||||
# Arbeitsverzeichnis setzen
|
# 2. System-Abhängigkeiten installieren
|
||||||
WORKDIR /app
|
# Installiert alle notwendigen Bibliotheken für Chrome und nützliche Tools wie wget.
|
||||||
|
# Die Option --no-install-recommends hält das Image klein.
|
||||||
# Systemabhängigkeiten für Google Chrome installieren
|
# rm -rf /var/lib/apt/lists/* räumt den apt-Cache auf, um Speicherplatz zu sparen.
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
wget \
|
wget \
|
||||||
unzip \
|
unzip \
|
||||||
gnupg \
|
gnupg \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
# Chrome-Bibliotheken
|
fonts-liberation \
|
||||||
libnss3 \
|
libasound2 \
|
||||||
libxss1 \
|
|
||||||
libatk1.0-0 \
|
|
||||||
libatk-bridge2.0-0 \
|
libatk-bridge2.0-0 \
|
||||||
|
libatk1.0-0 \
|
||||||
libcups2 \
|
libcups2 \
|
||||||
libdrm2 \
|
|
||||||
libdbus-1-3 \
|
libdbus-1-3 \
|
||||||
libgbm1 \
|
|
||||||
libgdk-pixbuf2.0-0 \
|
libgdk-pixbuf2.0-0 \
|
||||||
libgtk-3-0 \
|
libnspr4 \
|
||||||
libatspi2.0-0 \
|
libnss3 \
|
||||||
|
libx11-xcb1 \
|
||||||
|
libxcomposite1 \
|
||||||
|
libxdamage1 \
|
||||||
|
libxrandr2 \
|
||||||
|
xdg-utils \
|
||||||
--no-install-recommends && \
|
--no-install-recommends && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Google Chrome Stable installieren
|
# 3. Google Chrome Stable installieren
|
||||||
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
|
# Fügt das offizielle Google-Repository hinzu und installiert die stabile Chrome-Version.
|
||||||
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
|
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
|
||||||
&& apt-get update \
|
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
|
||||||
&& apt-get install -y google-chrome-stable \
|
apt-get update && \
|
||||||
--no-install-recommends \
|
apt-get install -y google-chrome-stable --no-install-recommends && \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Passenden Chromedriver installieren
|
# 4. Passenden Chromedriver installieren
|
||||||
# Diese Methode ist robust und findet die passende Version dynamisch
|
# Dieser Block ermittelt dynamisch die Version des gerade installierten Chrome
|
||||||
RUN CHROME_VERSION=$(google-chrome --version | cut -f 3 -d ' ' | cut -d '.' -f 1-3) \
|
# und lädt exakt die dazu passende Chromedriver-Version herunter.
|
||||||
&& DRIVER_VERSION=$(wget -qO- "https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build.json" | grep -A1 "\"${CHROME_VERSION}\"" | grep "version" | cut -d '"' -f 4) \
|
RUN CHROME_VERSION=$(google-chrome --version | awk '{print $3}') && \
|
||||||
&& wget -q "https://storage.googleapis.com/chrome-for-testing-public/${DRIVER_VERSION}/linux64/chromedriver-linux64.zip" -O /tmp/chromedriver.zip \
|
CHROMEDRIVER_VERSION=$(wget -qO- https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION%.*}) && \
|
||||||
&& unzip /tmp/chromedriver.zip -d /usr/local/bin/ \
|
wget -O /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip && \
|
||||||
&& mv /usr/local/bin/chromedriver-linux64/chromedriver /usr/local/bin/ \
|
unzip /tmp/chromedriver.zip -d /usr/local/bin/ && \
|
||||||
&& rm -rf /tmp/chromedriver.zip /usr/local/bin/chromedriver-linux64 \
|
chmod +x /usr/local/bin/chromedriver && \
|
||||||
&& chmod +x /usr/local/bin/chromedriver
|
rm /tmp/chromedriver.zip
|
||||||
|
|
||||||
# Python-Abhängigkeiten installieren
|
# 5. App-Verzeichnis einrichten
|
||||||
COPY app/requirements.txt .
|
# Setzt das Standard-Arbeitsverzeichnis im Container auf /app.
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
WORKDIR /app
|
||||||
|
|
||||||
# Den App-Code in den Container kopieren
|
# 6. Anwendungsdateien kopieren
|
||||||
COPY app/ .
|
# Kopiert ALLE Dateien aus dem aktuellen Verzeichnis (wo das Dockerfile liegt)
|
||||||
|
# in das /app Verzeichnis im Container. Dies ist die entscheidende Zeile für deine flache Dateistruktur.
|
||||||
|
COPY . .
|
||||||
|
|
||||||
# Standard-Befehl zum Ausführen des Skripts
|
# 7. Python-Abhängigkeiten installieren
|
||||||
|
# Liest die requirements.txt und installiert die Pakete mit pip.
|
||||||
|
RUN pip3 install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# 8. Standard-Startbefehl festlegen
|
||||||
|
# Dieser Befehl wird ausgeführt, wenn der Container gestartet wird.
|
||||||
|
# Er startet dein Haupt-Skript mit Python 3.
|
||||||
CMD ["python3", "scrape_fotograf.py"]
|
CMD ["python3", "scrape_fotograf.py"]
|
||||||
Reference in New Issue
Block a user