What's the best practice for building Docker for Python — using requirements file OR installing individually?
Using requirements file
86%
Installing packages individually
14%
7 votes · Closed
I am trying to create a Docker image for my Python/Django application. Which method would be best to follow?
1. Using requirements file
ADD requirements.txt /code/requirements.txt
RUN pip install -r requirements.txt
OR
2. Installing packages individually
RUN pip install package1 package2 package3
RUN pip install package4 package5
One good thing I find with second approach is that cache can be re-used. Each new line of pip install will be added when a new version is being made, ie, one release will have at-most one line on pip install packages.
I feel that first approach will invalidate the cache as requirements file will change when new packages are added, and all the packages are re-installed.
Which method do you prefer?
Please support your answers with reasons.