Skip to content
Advertisement

Why TensorFlow CPU 2.7.0 is not found by docker while creating an image?

I am building a docker image, using this Dockerfile:

FROM python:3.8-alpine
EXPOSE 5000/tcp
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD [ "python", "./app.py" ]

This is the command I used:

docker build -t my-language-app:1.0 .

And it is giving this error:

[+] Building 91.5s (9/9) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for docker.io/library/python:3.8-alpine                                               3.3s
 => [auth] library/python:pull token for registry-1.docker.io                                                      0.0s
 => [internal] load build context                                                                                  0.0s
 => => transferring context: 3.71kB                                                                                0.0s
 => [1/4] FROM docker.io/library/python:3.8-alpine@sha256:ae21a996ebe902ddc73cff020202d94cb539c8c4426f67636374b32  0.0s
 => CACHED [2/4] WORKDIR /app                                                                                      0.0s
 => [3/4] COPY . /app                                                                                              2.0s
 => ERROR [4/4] RUN pip install -r requirements.txt                                                               86.1s
------
 > [4/4] RUN pip install -r requirements.txt:
#9 5.199 Collecting Flask==1.1.2
#9 5.529   Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
#9 8.898 Collecting numpy
#9 8.978   Downloading numpy-1.21.4.zip (10.6 MB)
#9 64.97   Installing build dependencies: started
#9 84.51   Installing build dependencies: finished with status 'done'
#9 84.51   Getting requirements to build wheel: started
#9 85.15   Getting requirements to build wheel: finished with status 'done'
#9 85.15     Preparing wheel metadata: started
#9 85.64     Preparing wheel metadata: finished with status 'done'
#9 85.88 ERROR: Could not find a version that satisfies the requirement tensorflow-cpu==2.7.0 (from versions: none)
#9 85.88 ERROR: No matching distribution found for tensorflow-cpu==2.7.0
#9 85.89 WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
#9 85.89 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
------
executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1

Why it can’t find tensorflow-cpu==2.7.0, when this TensorFlow version is available. What’s wrong?

Here is my requirements.txt:

Flask==1.1.2
numpy
tensorflow-cpu==2.7.0

What is not working:

  1. Just writing tensorflow in requirements.txt is also not working.
  2. Removing tensorflow from requirements.txt and adding this RUN python3.8 -m pip install tensorflow command on Dockerfile, also not working.
  3. Running this command in Dockerfile pip3 install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.7.0-cp39-cp39-win_amd64.whl also not working.
  4. Changing Python version in Dockerfile FROM python:3.8-alpine to 3.9, 3.7, 3.6 not working.

Advertisement

Answer

After digging through the internet and searching, the main issue here which is similar to mine is that there is no native support from TensorFlow for linux/arm64 architecture till now 22-01-2022.

The error is a result of not finding a package for the linux/arm64 image, so to solve this we can force the platform to be x86-64 architecture and run the container through emulation by the following steps:

  1. Adding this FROM --platform=linux/amd64 python:3.8-alpine instead of FROM python:3.8-alpine to your Dockerfile or use whatever container you want. But make sure that the container image supports ur OS and architecture before adding he --platform argument. Without adding this argument Docker chooses linux/arm64 because it will have better compatibility with the arm64 host.

  2. (For Mac OS Montrey and any framework that uses port 5000 like Python Flask only) Then, you will find that port 5000 is used. This is due to airplay listening on this port, you can disable this by going to ‘System Preferences -> Sharing’ and uncheck AirPlay Receiver. You can enable it later after finishing your development or change the port used by your app.

  3. You will then find further complications with ‘qemu’, the docker’s hypervisor that emulates x86-64 on arm64 giving you the following error qemu: uncaught target signal 6 (Aborted) - core dumped, this happens because TensorFlow uses AVX instructions which aren’t supported in qemu explained furtherly here https://gitlab.com/qemu-project/qemu/-/issues/164. You can use a community package that’s built with No AVX from here https://github.com/yaroslavvb/tensorflow-community-wheels/issues and force the reinstallation to keep your requirements file intact like this RUN python -m pip install --force-reinstall https://tf.novaal.de/barcelona/tensorflow-2.7.0-cp38-cp38-linux_x86_64.whl

Finally, build and run your container and everything should hopefully work.


Alternative solution which I haven’t tested yet, which is to build a customer TensorFlow package for linux/arm64. You can find a GitHub repo here doing so and building a docker container from it https://github.com/ARM-software/Tool-Solutions/tree/master/docker/tensorflow-aarch64

Or, you can download the container directly from DockerHub from the following link https://hub.docker.com/r/armswdev/tensorflow-arm-neoverse/ , then you can build above that image whatever tools you want or use it for development.

Disclaimer: I’m not the owner of any of the above repos and you should use it under your own discretion.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement