Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why are Python project files copied after installing requirements in dockerfile and not before?

Take the sample from https://docs.docker.com/language/python/build-images/ for instance:

# ...

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

COPY . .

# ...

vs

# ...

COPY . .
RUN pip3 install -r requirements.txt

# ...

What are the disadvantages of the latter?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Docker checks every ADD and COPY statement to see if any files have changed and invalidate the cache for it and every later step if it has.

So, in the later, after changes in your code, all requirements will be reinstalled.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading