Skip to content

Commit

Permalink
feat : use --no-cache-dir flag to pip in dockerfiles to save space (#334
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 <[email protected]>
  • Loading branch information
Rajpratik71 authored Sep 21, 2024
1 parent 14ed7c9 commit 46bf945
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ WORKDIR /app

COPY ./requirements.txt requirements.txt

RUN pip install --upgrade pip
RUN pip install --no-cache-dir --upgrade pip
# Install the project dependencies
RUN python -m ensurepip --upgrade
RUN pip install -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion docker/aws.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apt-get update && \
COPY ./requirements.txt requirements.txt

# Install the project dependencies
RUN pip install -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Install curl and unzip for awscli
RUN apt-get -y update; apt-get -y install curl; apt-get -y install unzip
Expand Down

0 comments on commit 46bf945

Please sign in to comment.