FastAPI Docker Quick and Easy Setup | Deploy FastAPI with Docker in minutes along with TensorFlow

Опубликовано: 15 Октябрь 2024
на канале: Abdul Rehman 2050
49
0

FastAPI Docker Example file with TensorFlow, keras and uvicorn demonstration video. This video is about running a simple fastAPI based python application using docker. Which is simply containerizing the FASTAPI App with Docker. I demonstrated in this video how simple it is to run a python based FastAPI app to run using the docker image. Here is the Dockerfile used in this video


Use the official Python base image
FROM python:3.11.6-slim

Set environment variables to prevent Python from writing .pyc files and buffering stdout/stderr
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1



Upgrade pip and install Python dependencies
RUN pip install --upgrade pip
RUN pip install opencv-python-headless tensorflow==2.14.0 keras==2.14.0 fastapi==0.110.0 uvicorn==0.22.0

Set the working directory
WORKDIR /app

Copy the FastAPI app into the container
COPY app.py /app

Expose the port that the app will run on
EXPOSE 8000

Command to run the FastAPI app using Uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]


and here is the app.py file

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
return {"Hello": "World"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}


other related words to search this video are

docker,docker tutorial,python docker,fastapi docker,docker container,docker fastapi,docker compose,docker basics,docker postgres,fastapi docker container,learn docker,docker python,fastapi with docker,docker hub,fastapi docker deploy,docker app,docker image,docker images,what is docker,fastapi with docker compose,docker mongodb,fastapi docker mircroservice,docker compose up,docker community,docker containers,docker compose yml