0

Every time I build the image and run it and then delete it. Then after I want to run this image again after changing some code in our application, then all the requirements.txt file and the base image python:3 will be downloaded again. Then what I have to stop again downloading the requirements.txt file every time. Can you give me any solution?

Just have a look of my Dockerfile

FROM  python:3
ADD . /usr/src/app
WORKDIR /usr/src/app
RUN pip3 install -r requirements.txt
EXPOSE 5050
CMD [ "python", "app.py" ]
Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100

1 Answers1

0

Add the requirements separately. The layer with pip3 install will only be executed again when requirements.txt changes.

FROM  python:3
ADD requirements.txt /usr/src/app/requirements.txt
WORKDIR /usr/src/app
RUN pip3 install -r requirements.txt
ADD . /usr/src/app
EXPOSE 5050
CMD [ "python", "app.py" ]
Botje
  • 26,269
  • 3
  • 31
  • 41