1

I have a DockerFile which has command

RUN pip install --index-url=<url> -r requirements.txt

requirements.txt contain all the dependencies. These dependencies are packages and I want always the latest package. Each time even if a single dependency is changed, the image is rebuild and all the dependencies are downloaded and built. Is there a way to update the existing image or create a new image with all the dependencies but do not download the dependencies which have not changed and download only the ones which have changed.

nname
  • 59
  • 1
  • 9
  • [Using a pip cache directory in docker builds](https://stackoverflow.com/q/58018300/10008173) discusses an approach to avoid downloading packages again on repeated builds, which tends to be the majority of the time; does that help you? – David Maze Jun 27 '20 at 18:27

1 Answers1

0

Could you adopt this example to your needs? As I remember, this Dockerfile template could reinstall only packages, which has been changed:

ARG CODE_VERSION="3.8-slim"
ARG PROJECT_DIR = "main_project"
FROM python:${CODE_VERSION}
COPY ./requirements.txt ./${PROJECT_DIR}/requirements.txt
WORKDIR /${PROJECT_DIR}
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . /${PROJECT_DIR}
Dmitriy Kisil
  • 2,858
  • 2
  • 16
  • 35