From acf15d4802e2a6b52294eacc83d381b8468b6e4a Mon Sep 17 00:00:00 2001 From: Sergio Alonso Date: Tue, 3 Nov 2026 15:17:14 +0100 Subject: [PATCH] Improve dockerfile Split into a multi-step build, use a -slim base image and run the service as a non-root user --- challenges/shrink-the-image/Dockerfile | 28 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/challenges/shrink-the-image/Dockerfile b/challenges/shrink-the-image/Dockerfile index 1ac445d..02934a5 100644 --- a/challenges/shrink-the-image/Dockerfile +++ b/challenges/shrink-the-image/Dockerfile @@ -1,15 +1,25 @@ -FROM python:3.13 - -RUN apt-get update && apt-get install -y \ - build-essential \ - curl \ - git \ - vim +FROM python:3.13-slim AS build WORKDIR /app -COPY . . +COPY app.py requirements.txt . + +RUN apt-get update +RUN apt-get install -y --no-install-recommends build-essential + +RUN adduser slug +USER slug + +RUN pip install --user -r requirements.txt -RUN pip install -r requirements.txt -r requirements-dev.txt +FROM python:3.13-slim AS runner + +RUN adduser slug +USER slug + +WORKDIR /app +COPY --from=build /app/app.py /app +COPY --from=build /home/slug/.local /home/slug/.local +ENV PATH=/home/slug/.local/bin:$PATH EXPOSE 8000 CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "app:app"]