Skip to content

Commit

Permalink
feat : use --no-cache-dir flag to pip in dockerfiles to save space
Browse files Browse the repository at this point in the history
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 <Rajpratik71@gmail.com>
  • Loading branch information
Rajpratik71 committed Oct 10, 2022
1 parent 5cf7f2e commit 7fe1c49
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Expand Up @@ -12,17 +12,17 @@ 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/
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

Expand Down

0 comments on commit 7fe1c49

Please sign in to comment.