From ccd81766f7b1c3098e4af6f8b44c070ab5efad8f Mon Sep 17 00:00:00 2001 From: comrumino Date: Mon, 16 Jan 2023 15:41:35 -0600 Subject: [PATCH 1/2] Removed Dockerfile command to install the latest version of psycopg2 since requirements.txt specifies 2.8.6 --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ae8ea61..738168c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,7 @@ FROM python:3.8-slim-buster WORKDIR /app RUN apt-get update \ - && apt-get -y install libpq-dev gcc \ - && pip3 install psycopg2 + && apt-get -y install libpq-dev gcc COPY requirements.txt requirements.txt RUN pip3 install -r requirements.txt From 277f2d6e51aebae61ef22fbaa4d72f2bd77be34d Mon Sep 17 00:00:00 2001 From: comrumino Date: Mon, 16 Jan 2023 19:43:34 -0600 Subject: [PATCH 2/2] Reduce built docker images size by roughly 40% (135MB) by using multistage build so build deps arent distributed for runtime --- Dockerfile | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 738168c..2de0dab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,16 @@ -FROM python:3.8-slim-buster +FROM python:3.8-slim-buster AS builder +# Builder stage dependencies aren't needed by the app at runtime +RUN apt-get update && apt-get install -y \ + libpq-dev \ + gcc +COPY requirements.txt . +RUN pip install --upgrade pip setuptools wheel +RUN pip install -r requirements.txt +FROM python:3.8-slim-buster AS app WORKDIR /app - -RUN apt-get update \ - && apt-get -y install libpq-dev gcc - -COPY requirements.txt requirements.txt -RUN pip3 install -r requirements.txt - +RUN apt-get update && apt-get install -y libpq5 \ + && rm -rf /var/lib/apt/lists/* +COPY --from=builder /usr/local /usr/local/ COPY . . - -CMD ["/bin/bash","run.sh"] +CMD ["/bin/bash", "run.sh"]