3

I am trying to install tensorflow in docker image for my application.

I have 3 files in the folder which i am using to build image.Dockerfile, index.py and requirements.txt

Contents of these files are

Dockerfile

FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip3 install -r requirements.txt
EXPOSE 5000
CMD python ./index.py

requirements.txt

tensorflow==1.1.0
scikit-learn==0.18.2
scipy==0.19.1
numpy==1.13.1
requests==2.18.3

index.py

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
    return "Hello World!"
if __name__ == "__main__":
    app.run(host="0.0.0.0", port=int("5000"), debug=True)

I navigate in the commandline to the folder where i have these 3 files in my windows machine and execute the command docker build --tag my-python-app2 .

After a while, after executing a while, i get below error message.

C:\Users\test\Downloads\python-docker2>docker build --tag my-python-app2 .
Sending build context to Docker daemon  4.096kB
Step 1/6 : FROM python:alpine3.7
 ---> cc07d9ec6532
Step 2/6 : COPY . /app
 ---> Using cache
 ---> 600334d62435
Step 3/6 : WORKDIR /app
 ---> Using cache
 ---> 15208b829606
Step 4/6 : RUN pip3 install -r requirements.txt
 ---> Running in e202ecdc48ba
Collecting tensorflow==1.1.0 (from -r requirements.txt (line 1))
  Could not find a version that satisfies the requirement tensorflow==1.1.0 (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for tensorflow==1.1.0 (from -r requirements.txt (line 1))
The command '/bin/sh -c pip3 install -r requirements.txt' returned a non-zero code: 1

Can anyone help on this?

2
  • What version of pip3 is inside that image? Before step 4 what happens if you try to upgrade pip3 first to the latest version? Commented Sep 26, 2018 at 15:52
  • I just tried that and added RUN pip3 install --upgrade pip before RUN pip3 install -r requirements.txt and still got the same error Commented Sep 26, 2018 at 15:55

1 Answer 1

3

I found the answer myself. I changed the line for tensorflow to RUN python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl in Dockerfile and removed it from requirements.txt

Sign up to request clarification or add additional context in comments.

3 Comments

You said you are working on a Windows machine, so why are you using Mac .whl file?
I am facing same problem here stackoverflow.com/questions/70337271/… do you have any solution?
Your own answer looks like only for "Tensorflow" tool. Should I use repeately this line for all other software libraries? Or I could use RUN pip install -r requirements.txt after the line (ref: stackoverflow.com/a/34399661/5595995)?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.