Reputation: 103
I made a test flask application that looks like the following:
from flask import Flask
from flask_cors import CORS
import os
app = Flask(__name__)
CORS(app)
@app.route('/')
def hello_word():
return 'hello', 200
if __name__ == '__main__':
app.run(threaded=True, host='0.0.0.0', port=int(os.environ.get("PORT", 8080)))
However, if i host this application on Azure Container Instance, the application never "stops". The memory usage is always at around 50mb and I'm constantly getting charged. If I host the same application on Google Cloud run, I'm only charged for the request time (20ms or so). The following is my dockerfile
FROM python:3.9-slim
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
RUN pip install Flask gunicorn
ENV PORT=80
CMD exec gunicorn --bind :$PORT --workers 3 --threads 3 --timeout 100 main:app --access-logfile -
Any thoughts on how to stop the container instance once the request is served on Azure?
Upvotes: 0
Views: 274
Reputation: 31384
Actually, the ACI just run the image for you and nothing else. It means if your image has an application that keeps running, then the ACI keeps running. And it seems you need to schedule to stop the ACI, maybe you can try the Azure logic App. You can use it to create the ACI and then stop it after a period that you need.
Upvotes: 2