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.