I tried to deploy a instance of a simple FastAPI service into azure.
I have tried several ways, using uvicorn as server, using gunicorn with uvicorn workers, using an image from Docker Hub, uploading the image to Container Registry in Azure...
When I create the Docker image and run it at local it works perfectly, but then in Azure is not working.
This is my main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"msg": "Hola FastAPI!!"}
@app.get("/url")
async def url():
return {"url": "http://whatever.es"}
This is my Dockerfile
# syntax=docker/dockerfile:1
FROM python:3.11
WORKDIR /code
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["gunicorn" ,"--config", "gunicorn.py", "main:app"]
This is the gunicorn.py configuration file:
# Gunicorn configuration file
import multiprocessing
bind = "0.0.0.0:8000"
worker_class = "uvicorn.workers.UvicornWorker"
workers = multiprocessing.cpu_count() * 2 + 1
This is my requirements.txt
fastapi
uvicorn
gunicorn
As I told you, all the process seem to be ok until the last step, after the deployment, I got this message and the server is not listening in the port 8000. In local it works perfectly.
As you can see it says that is in a waiting state.
I appreciate your help.
I have tried to execute my container image in an Azure Container Instance.
I am expecting to have my service running in :8000
The result is that is nothing running there
I used your code to create this project and successfully deployed the image to the Azure Container Registry.
Ensure that your ACI has sufficient CPU, memory, and other resources allocated to it.
Check the logs for your Azure Container Instance to see if there are any error messages or warnings.
Verify that the container images specified in your ACI configuration are accessible and properly configured.
gunicorn. py:
I used the commands below to build and run FastAPI in a Docker.
I ran the commands below to push the Docker image to the Azure Container Registry.
I created an Azure Container Instance in the Azure Portal, as shown below.
Output: