Reduce Docker image size

This commit is contained in:
ngosang 2022-09-24 18:29:44 +02:00
parent 33bed9428e
commit f10f7269ca

View File

@ -1,22 +1,44 @@
FROM python:3.10.5-slim-bullseye FROM python:3.10-slim-bullseye as builder
WORKDIR /app # Build dummy packages to skip installing them and their dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends equivs \
&& equivs-control libgl1-mesa-dri \
&& printf 'Section: misc\nPriority: optional\nStandards-Version: 3.9.2\nPackage: libgl1-mesa-dri\nVersion: 99.0.0\nDescription: Dummy package for libgl1-mesa-dri\n' >> libgl1-mesa-dri \
&& equivs-build libgl1-mesa-dri \
&& mv libgl1-mesa-dri_*.deb /libgl1-mesa-dri.deb \
&& equivs-control adwaita-icon-theme \
&& printf 'Section: misc\nPriority: optional\nStandards-Version: 3.9.2\nPackage: adwaita-icon-theme\nVersion: 99.0.0\nDescription: Dummy package for adwaita-icon-theme\n' >> adwaita-icon-theme \
&& equivs-build adwaita-icon-theme \
&& mv adwaita-icon-theme_*.deb /adwaita-icon-theme.deb
# Install dependencies and create user FROM python:3.10-slim-bullseye
# Copy dummy packages
COPY --from=builder /*.deb /
# Install dependencies and create flaresolverr user
# We have to install and old version of Chromium because its not working in Raspberry Pi / ARM # We have to install and old version of Chromium because its not working in Raspberry Pi / ARM
# You can test Chromium running this command inside the container: # You can test Chromium running this command inside the container:
# xvfb-run -s "-screen 0 1600x1200x24" chromium --no-sandbox # xvfb-run -s "-screen 0 1600x1200x24" chromium --no-sandbox
# The error traces is like this: "*** stack smashing detected ***: terminated" # The error traces is like this: "*** stack smashing detected ***: terminated"
# To check the package versions available you can use this command: # To check the package versions available you can use this command:
# apt-cache madison chromium # apt-cache madison chromium
WORKDIR /app
RUN echo "\ndeb http://snapshot.debian.org/archive/debian/20210519T212015Z/ bullseye main" >> /etc/apt/sources.list \ RUN echo "\ndeb http://snapshot.debian.org/archive/debian/20210519T212015Z/ bullseye main" >> /etc/apt/sources.list \
&& echo 'Acquire::Check-Valid-Until "false";' | tee /etc/apt/apt.conf.d/00snapshot \ && echo 'Acquire::Check-Valid-Until "false";' | tee /etc/apt/apt.conf.d/00snapshot \
# Install dummy packages
&& dpkg -i /libgl1-mesa-dri.deb \
&& dpkg -i /adwaita-icon-theme.deb \
# Install dependencies
&& apt-get update \ && apt-get update \
&& apt-get install -y --no-install-recommends chromium=89.0.4389.114-1 chromium-common=89.0.4389.114-1 \ && apt-get install -y --no-install-recommends chromium=89.0.4389.114-1 chromium-common=89.0.4389.114-1 \
chromium-driver=89.0.4389.114-1 xvfb xauth \ chromium-driver=89.0.4389.114-1 xvfb \
# Clean # Remove temporary files and hardware decoding libraries
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/* \
# Create user && rm /usr/lib/x86_64-linux-gnu/libmfxhw* \
&& rm /usr/lib/x86_64-linux-gnu/mfx/* \
# Create flaresolverr user
&& useradd --home-dir /app --shell /bin/sh flaresolverr \ && useradd --home-dir /app --shell /bin/sh flaresolverr \
&& mv /usr/bin/chromedriver chromedriver \ && mv /usr/bin/chromedriver chromedriver \
&& chown -R flaresolverr:flaresolverr . && chown -R flaresolverr:flaresolverr .
@ -24,7 +46,7 @@ RUN echo "\ndeb http://snapshot.debian.org/archive/debian/20210519T212015Z/ bull
# Install Python dependencies # Install Python dependencies
COPY requirements.txt . COPY requirements.txt .
RUN pip install -r requirements.txt \ RUN pip install -r requirements.txt \
# remove temporary files # Remove temporary files
&& rm -rf /root/.cache \ && rm -rf /root/.cache \
&& find / -name '*.pyc' -delete && find / -name '*.pyc' -delete
@ -37,5 +59,11 @@ EXPOSE 8191
CMD ["/usr/local/bin/python", "-u", "/app/flaresolverr.py"] CMD ["/usr/local/bin/python", "-u", "/app/flaresolverr.py"]
# docker build -t flaresolverr:3.0.0.beta1 . # Local build
# docker run -p 8191:8191 flaresolverr:3.0.0.beta1 # docker build -t ngosang/flaresolverr:3.0.0.beta2 .
# docker run -p 8191:8191 ngosang/flaresolverr:3.0.0.beta2
# Multi-arch build
# docker buildx create --use
# docker buildx build -t ngosang/flaresolverr:3.0.0.beta2 --platform linux/386,linux/amd64,linux/arm/v7,linux/arm64/v8 .
# add --push to publish in DockerHub