I have created a Dockerfile as shown below:
FROM tensorflow/tensorflow:latest
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./app /code/app
CMD ["fastapi", "run", "app/main.py", "--port", "80"]
and requirements.txt file with following values:
fastapi>=0.110.0,<0.113.0
pydantic>=2.7.0,<3.0.0
tensorflow
I am using the following command to build the docker and run it then
docker build --platform=linux/arm64/v8 -t myimage .
docker run -d --name mycontainer -p 80:80 myimage
and main function has following code:
from typing import Union
from fastapi import FastAPI, Request
# from tensorflow import keras
# import tensorflow
# model = keras.models.load_model("app/my_model.keras")
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
Whenever i try to import tensorflow in above main file there is an error coming in Docker run. Any resolution for the same
I tried changing the From path to python 3.9 but it was causing compilation error while installing tensorflow.
2
Answers
If you may, try with an image that’s a better match.
Check for the best match for ARM and the dependencies.
if you are running docker on Mac M1 or later versions you won’t be able to use prebuild docker images. At least as of Today.
I have Mac Por M1. I have checked several versions of prebuilt docker images:
Tensorflow 2.9 version:
This will give an error:
Tensorflow 2.16 (latest as of Today) version.
This simply outputs
I have also testes prebuilt images with versions between 2.9 and 2.16 and neither of them works on the Mac. However this was expected, I guess…
Thus I would conclude that the only option is to compile custom docker tensorflow image that supports mac with ARM64.