From 056e5f2ac70118d647771086cec20b182d3a48a9 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Date: Wed, 1 Oct 2025 17:39:12 +0800 Subject: [PATCH] [UPDT] Using docker multi-stage builds to reduce docker image's size (#925) * [UPDT] Using docker multi-stage builds to reduce docker image's size * [FIX] Updating WORKDIR for consistency --- Dockerfile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 270a6e096..5708d4428 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,26 @@ -FROM python:3.10-slim-bullseye +FROM python:3.10-slim-bullseye AS builder ENV PYTHONUNBUFFERED=1 -RUN apt-get update && apt-get install -y libcairo2-dev gcc +RUN apt-get update && apt-get install -y --no-install-recommends libcairo2-dev gcc && rm -rf /var/lib/apt/lists/* WORKDIR /app/ +COPY requirements.txt . +RUN pip install --no-cache-dir --prefix=/install -r requirements.txt + +FROM python:3.10-slim-bullseye AS runtime + +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app/ + +COPY --from=builder /install /usr/local + COPY . . RUN chmod +x /app/entrypoint.sh -RUN pip install -r requirements.txt - EXPOSE 8000 CMD ["python3", "manage.py", "runserver"]