From 7fe1c498700e3afbd20e2838e3a610cb6c691fdb Mon Sep 17 00:00:00 2001 From: Pratik Raj Date: Mon, 10 Oct 2022 15:00:07 +0530 Subject: [PATCH] feat : use `--no-cache-dir` flag to `pip` in dockerfiles to save space using the "--no-cache-dir" flag in pip install, make sure downloaded packages by pip don't cache on the system. This is a best practice that makes sure to fetch from a repo instead of using a local cached one. Further, in the case of Docker Containers, by restricting caching, we can reduce image size. In terms of stats, it depends upon the number of python packages multiplied by their respective size. e.g for heavy packages with a lot of dependencies it reduces a lot by don't cache pip packages. Further, more detailed information can be found at https://medium.com/sciforce/strategies-of-docker-images-optimization-2ca9cc5719b6 Signed-off-by: Pratik Raj --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c9dcc36f7..8c72b15be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,9 +12,9 @@ WORKDIR /app COPY requirements /app/requirements # py dev tooling -RUN python3 -m pip install --upgrade pip && python3 --version -RUN pip3 install --upgrade setuptools -RUN pip3 install -r requirements/app.txt -r requirements/dev.txt -r requirements/test.txt +RUN python3 -m pip install --no-cache-dir --upgrade pip && python3 --version +RUN pip3 install --no-cache-dir --upgrade setuptools +RUN pip3 install --no-cache-dir -r requirements/app.txt -r requirements/dev.txt -r requirements/test.txt # Copy code and meta/config data COPY setup.* .flaskenv wsgi.py /app/ @@ -22,7 +22,7 @@ COPY flexmeasures/ /app/flexmeasures RUN find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf COPY .git/ /app/.git -RUN pip3 install . +RUN pip3 install --no-cache-dir . EXPOSE 5000