skip to Main Content

I’ve deployed a FastAPI application containerized with Docker to Azure App Service. The deployment appears successful, and the application logs indicate that it’s running, but I can’t get any HTTP response when accessing the app through the Azure-provided URL. I’m seeking advice on how to diagnose and resolve this issue.

Environment:

  • Language/Framework: Python 3.9, FastAPI
  • Containerization: Docker
  • Hosting: Azure App Service (Web App for Containers)
  • Deployment Method: Deployed using Azure Portal with a Docker image from Azure Container Registry

Dockerfile:

FROM python:3.9
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

I restarted the Azure App Service multiple times.
Reviewed application logs in Azure Portal (Monitoring > Log stream), which did not reveal any errors related to the lack of HTTP response.
Ensured there are no firewall or network security settings in Azure that could be blocking incoming traffic to the app.
Given that the application works locally and the Docker container seems to be running fine on Azure (according to the logs), I’m puzzled about what could be going wrong.

Could the issue be related to Azure App Service expecting the application to listen on a different port, or might there be another configuration step I’m missing?

Any insights, suggestions, or troubleshooting tips would be greatly appreciated!

2

Answers


  1. @PGHE thanks for comment.

    I attempted the simple code below, containerized it with Docker, and successfully deployed it to the Azure App Service.

    This is my main. py:

    from fastapi import FastAPI
    app = FastAPI()
    @app.get("/")
    def read_root():
        return {"Hello": "World"}
    

    Dockerfile:

    FROM python:3.9
    WORKDIR /app
    COPY requirements.txt .
    RUN pip install --no-cache-dir -r requirements.txt
    COPY . .
    EXPOSE "8000"
    CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
    

    requirements.txt:

    fastapi==0.109.2
    uvicorn==0.27.0
    

    Use the commands below to build and run the FastAPI in a Docker image:

    docker build -t <ImageName> . 
    docker run -p 8000:8000 <ImageName> 
    

    Local Output:

    enter image description here

    I ran the following commands to push the image to the Azure Container Registry:

    az acr login -n <ContainerUserName> -u <userName> -p <Password>
    docker tag <ImageName> <AzureContainerRegistryName>.azurecr.io/pyfastapi-app:<tagName>
    docker push <AzureContainerRegistryName>.azurecr.io/<ImageName>:<tagName>
    

    When I created a web app in Azure, I selected the "Publish" option as "Docker Container" as shown below.

    enter image description here

    enter image description here

    Azure App Service Output:

    enter image description here

    Login or Signup to reply.
  2. I was having the same trouble than you and have tried the solution proposed by Aslesha, but I’m still having the problem: I got the ":( Application Error" on 80 port and a 404 error on 8000 port.

    I have followed the steps carefully.

    Can anybody help?

    Thanks a lot.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search