From a7557ff4c1d216c9b48e856ac1774fd6200a3e48 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Tue, 19 Jan 2021 15:11:14 +0100 Subject: [PATCH] Remove dependencies after install to reduce image size --- middleware/Dockerfile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/middleware/Dockerfile b/middleware/Dockerfile index 92c9e3b..805a0f9 100644 --- a/middleware/Dockerfile +++ b/middleware/Dockerfile @@ -1,20 +1,22 @@ FROM python:3.8-slim ENV PYTHONUNBUFFERED 1 -RUN apt-get update -RUN apt-get install -y build-essential gcc RUN python -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" -RUN python -m pip install --upgrade pip - -ENV PATH="/opt/venv/bin:$PATH" - RUN mkdir /code WORKDIR /code COPY setup.py /code/ COPY requirements.txt /code/ -RUN pip install -r requirements.txt + +RUN buildDeps='gcc build-essential' \ + && apt update \ + && apt install -y --no-install-recommends $buildDeps \ + && rm -rf /var/lib/apt/lists/* \ + && pip install -r requirements.txt \ + && apt purge -y --auto-remove $buildDeps \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /root/.cache COPY . /code/