Home > OS >  Docker container is starting but isnt giving any response using FastApi
Docker container is starting but isnt giving any response using FastApi

Time:02-28

I just made a Fast api and deployed it using docker containers. But when running 127.0.0.1:5000 on browser it has empty response. Main.py file:

from fastapi import FastAPI
from starlette.status import HTTP_302_FOUND,HTTP_303_SEE_OTHER
import spacy
from string import punctuation
from mangum import Mangum

nlp = spacy.load("en_core_web_lg",disable=["tok2vec", "parser"])

app = FastAPI()

@app.get('/')
def home():
    return {"answer":"Hello World"}

@app.get('/tags')
def prep_data(text):
    tag = tokens(text, nlp)
    tags = getdict(tag)
    return {
        'tags':tags
    }

Docker file:

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8

COPY . /app

COPY ./requirements.txt /app/requirements.txt

WORKDIR /app

EXPOSE 5000

RUN pip install -r requirements.txt
RUN python -m spacy download en_core_web_lg

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]

File structure I am following:

/app
    main.py
Dockerfile
requirements.txt

These are all the contents and I am getting no response from the browser.

CodePudding user response:

You should also link the exposed port to an open port on the host machine when running the container.

docker run -dp <host_port>:<container_port> <image>
  • Related