Docker Community Forums

Share and learn in the Docker community.

How to persists python packages across multiple dockerfile builds

Hello forum, This is my first query.

I am trying to build a python container with pip python packages. It all works fine. But when I try to create new build using below dockerfile every time all the packages are downloaded and then built into image.

Downloading python packages file is slow for me and if some python package was failed to install or compile the image building fails and have to loop over same downloading. Consumes a lot time being on slow bandwidth.

I wish if there was ways to download & persist all the python packages to some local volume as well while image build itself and persists while rebuild.

How can this be done ? Here is my dockerfile:

FROM python:3.7.5-slim
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

Best regards,
Rajesh