Reputation: 785
I'm building an image from a Dockerfile where my main program is a python application that has a number of dependencies. The application is installed via setup.py
and the dependencies are listed inside. There is no requirements.txt
. I'm wondering if there is a way to avoid having to download and build all of the application dependencies, which rarely change, on every image build. I saw a number of solutions that use the requirements.txt
file but I'd like to avoid having one if possible.
Upvotes: 1
Views: 334
Reputation: 901
One solution is: if those dependencies rarely change as you said what you could do is another image with already those packages installed. You would create that image and then save it using docker save
, so you end with a new base image with the required dependencies. docker save
will create a .tar with the image. You have to load the image using docker load
and then in your Dockerfile
you would do:
FROM <new image with all the dependencies>
//your stuff and no need to run pip install
....
Hope it helps
Upvotes: 0
Reputation: 66311
You can use requires.txt
from the egg info to preinstall the requirements.
WORKDIR path/to/setup/script
RUN python setup.py egg_info
RUN pip install -r pkgname.egg-info/requires.txt
Upvotes: 2