I'm building a Docker image with a requirements.txt file. Every time I build the image it keeps failing due to some package version not being present. For example
ARG BASE_CONTAINER=tensorflow/tensorflow
FROM $BASE_CONTAINER
# 2) change to root to install packages
USER root
COPY requirements.txt requirements.txt
# 3) install packages
RUN pip install -r requirements.txt
ERROR: Could not find a version that satisfies the requirement msrestazure==0.5.4
(from -r requirements.txt (line 66)) (from versions: 0.0.1, 0.0.2, 0.1.0, 0.1.1, 0.1.2,
0.2.0, 0.2.1, 0.3.0, 0.4.0rc1, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.4.6, 0.4.7,
0.4.8, 0.4.9, 0.4.10, 0.4.11, 0.4.12, 0.4.13, 0.4.14, 0.4.15, 0.4.16, 0.4.17, 0.4.18,
0.4.19, 0.4.20, 0.4.21, 0.4.22, 0.4.23, 0.4.24, 0.4.25, 0.4.26, 0.4.27, 0.4.28, 0.4.29,
0.4.30, 0.4.31, 0.4.32, 0.4.33, 0.4.34, 0.5.0, 0.5.1, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.6.4)
#6 9.178 ERROR: No matching distribution found for msrestazure==0.5.4 (from -r requirements.txt (line 66))
To get around this I've just been changing the version of the package in my requirements.txt to the most up to date version that docker can find. I was wondering if there was a way to do this programmatically. Like is there some flag or option I can use to automatically install the latest version of the package that docker can find if the version I have in my requirements.txt file does not exist/cannot be found?
CodePudding user response:
Not specifying any version at all in a requirements.txt
will result in the most recent version being used, provided it does not conflict.
In your case I would suggest running docker run -it tensorflow/tensorflow
to get an interactive shell in the environment, then installing all your packages without a version specified. Test that that works, and if it does, run pip freeze > requirements.txt
to generate a new requirements file that works in that environment, so that your requirements can be stable.
You'll also have to pin the tensorflow/tensorflow
image, as if you use latest
as you're doing now then you can't be sure your requirements will be available in the future.
Make sure to copy the requirements.txt
file out before exiting the container.