FastApi container not running in a Container Instance

Norm Manuel 0 Reputation points
2024-03-17T00:16:06.4533333+00:00

I have created a docker image of a simple FastApi app, based in the example by Microsoft (using gunicorn as server), and also other FastApi made by me using only uvicorn as server.

I got this message: "one or more of the containers in XXXXX are in a Waiting state and may not be running"

Captura de pantalla 2024-03-17 a las 1.06.38

I have several different configurations but always same result.

If somebody can help me it would be very appreciated.

The main.py is very simple.


from fastapi import FastAPI
import uvicorn

app = FastAPI()


@app.get("/")
async def root():
    return {"msg": "Hola FastAPI!!"}


@app.get("/url")
async def url():
    return {"url": "http://midomain.es"}


if __name__ == "__main__":
    uvicorn.run("main:app", host="0.0.0.0", port=8000)

And this is the 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 3100

CMD ["gunicorn" ,"main:app"]

Finally this is the gunicorn.conf.py:

# Gunicorn configuration file
import multiprocessing

max_requests = 1000
max_requests_jitter = 50

log_file = "-"

bind = "0.0.0.0:3100"

worker_class = "uvicorn.workers.UvicornWorker"
workers = (multiprocessing.cpu_count() * 2) + 1

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
669 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anveshreddy Nimmala 3,460 Reputation points Microsoft Vendor
    2024-03-18T07:56:00.5733333+00:00

    Hello Norm Manuel,

    Welcome to microsoft Q&A,Thankyou for posting your query here.

    Screenshot 2024-03-18 125955

    I am able to create ACI run with the same image fastApi gunicorn server, as mentioned in the Microsoft document.(reddy3a7/fastapi-demo:latest (docker public image)).

    if you create a new ACI with different name and pull from the same image, it might works fine.

    there a note mentioned in ACR that if you are using free subscriptions, might effect the task.

    [! IMPORTANT] ACR is temporarily pausing ACR Tasks runs from Azure free credits.

    Hope this helps you

    If an answer has been helpful, please consider accepting the answer to help increase visibility of this question for other members of the Microsoft Q&A community. If not, please let us know what is still needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    0b4508e5-88d4-45d9-af45-6b9d1a7f7cd0

    0 comments No comments