How to Launch a FastAPI Service in Azure Containers in Less Than 10 Minutes!
Вставка
- Опубліковано 6 лип 2024
- In this video, we're going to show you how to have your FastAPI service up and running on Microsoft Azure Container Instances in UNDER 10 minutes!
If you're looking to get started with building your own cloud-based applications, then you'll want to check out this video. We'll teach you how to create a containerized Python FastAPI application, and then deploy the service to Azure Container Registry, and then finally fire it up into life through Azure Container Instances.
This quick and easy tutorial will have you up and running with FastAPI in no time!
-------------------------------------
What's on the agenda for today?
00:00 Introduction
00:14 Looking at the code
01:24 Running the service
02:29 Putting the app in a container
04:53 Getting the container onto Azure
08:17 Thanks for watching!
-------------------------------------
Check out the FastAPI docs for loads of extra things you can do:
fastapi.tiangolo.com/
For the code used in this video:
github.com/rowanlea/FastAPIEx...
-------------------------------------
If you need any help with Azure feel free to contact me through UA-cam or any of the links below.
My Links:
► Website: rowanlea.co.uk/
► GitHub: github.com/rowanlea
► LinkedIn: / rowan-lea
► Twitter: / rowanlea1
You can also message me personally at: mail@rowanlea.co.uk
-------------------------------------
Join in and don't miss out by subscribing and returning weekly for the freshest and most exciting videos around!
#azure #container #python #fastapi - Наука та технологія
Instead of re-building your docker image you can also just change the tag (thanks for the tip Sam):
`docker image tag `
dude
u just saved my life........
thanks and respect from INDIA...
Finally I found the easiest tutorial ever ! Thank you so much !!
Glad you found it useful! My main goal is to make my tutorials as quick and easy to understand as possible. Let me know if there's anything similar on Azure you think could do with a similar explanation to it!
Instant sub. Extremely fast, thorough and easy explanation.
Really appreciate it, thank you!!
Very well made. I was struggling for a few hours until I came across your video. Concise and straight to the point!
Thanks so much! Glad it helped you :)
Fast and to the point! Many thanks.
Damn, i not use to comment videos, but you deserve it. I send you a firm, solid and dry, 3 seconds hand shake sir.
Thank you so much! Glad you liked it 😊
Great tutorial. Thanks!
Thank so much please upload more more ...
Thank you! This helped a lot.
Glad you enjoyed it! Let me know if there's anything similar you'd like to see :) My most recent video shows you how to remote debug the app in this video!
Thanks Rowan, just what I was looking for!
Thanks! Glad it helped :)
Thank you so much 🙏
Glad you liked it!
Hi yes great and very easy to understand, although wanted to check if it is possible to change the IP to a more readable URL
Awesome tutorial!
Thanks very much, glad you enjoyed it!!
Thank you. Very useful. Does the IP change if we re-build the docker?
Great tutorial, very helpful! Everything still works
Edit: how do you make it https instead of http though
@@tessa10001 Glad you enjoyed it! If you change the port in the code to 443 that should be enough. When you set up a container it should have port 443 used for https bound by default. If that doesn't work give me a shout!
@@rowan-lea oh that is really helpful. I wont test this out though because i already set up a web app with this container instead
Great video! very detailed explainations! I have a quick question. The container published to Azure container registry will be public assessible as well? thx
wonderfully stripped down to essentials -- the MS documentation for the same need (deploy a FastAPI Python Server using docker in Azure) adds a lot of unnecessary steps if you just want a pure API server as you have shown, thanks!
Thank so much, glad you liked it!!
Thanks mate. Super useful. Any chance you can do a vid on debugging the code in the container on Azure?
Hey Alan, glad it helped! That's an awesome idea for a video, I'm going to add that to my list (very near the top, because that sounds like something very helpful to show).
You inspired me! ua-cam.com/video/82DEbrwqPvE/v-deo.html
I your video! To the point and helpful! I followed your video deployed a fastapi to Azure. Everything is fine when I do docker test locally. But the container instance I created cannot be started (kept being killed and start). If you have any insights?
Hey, glad you liked it! Do you mean it starts up initially and then ends straight away? I'm assuming this is consistent? Or it only starts some of the time?
Thanks for the explanation, it's very precise, sort and easy. The problem for me is simply that is not running, the container is stopped by Azure for no reason apparently every time that i try to run it. In the overview of the container I got a warning message: "One or more of the containers in 'fastapitest' are in a 'Waiting' state and may not be running'. I've tried with my own fastapi container and also with your exact same code from github. I wonder if Microsoft has change something. Thanks a lot!
Having the same issue - did you ever figure this out?
If you're looking to leverage GPU capabilities within your containerized applications on Azure, it's important to be aware that accessing GPU resources for Azure Container Instances requires applying for a quota. However, there's a possibility that your request might not be approved due to current limitations and high demand for GPU resources. (my application wasn't approved)
As a result, an alternative and more reliable approach would be to provision a Virtual Machine (VM) equipped with a GPU. You can then deploy your Docker containers on this VM. Additionally, it would be greatly beneficial for users like myself if you could provide a detailed tutorial on this process.
Awesome tutorial everything worked out but for the last part, after creating container instance i am trying to access with container’a IP but getting a gateway timeout error. Any idea?
Hey Suhas, sometimes it happens if you try to access the resources too quickly after creating them, it can take a couple of minutes for container resources to actually be created in the background (even after it says they're ready).
But also, are you using a similar "bare bones" set up like I am, or are you utilising any additional resources (like load balancers). Also, are all of your resources deployed to the same location? It shouldn't add enough time to cause a timeout error, but you never know!
Thanks I was able to get the public ip address but the problem is I need a https for integrating it with with frontend how can I do so ?
In the dockerfile you should be able to change the 80 on the last line to 443, this should do it for you, Azure Containers will have the port open by default for you.
what if Docker desktop is not available? wsl2 is not being installed on my machine to run docker. can someone help me please?
Hey, thank you so much for this amazing tutorial. I did everything you did step by step. I created the container instance.
I'm getting an error on Azure, "One or more of the containers in 'aci-fast-api' are in a 'Waiting' state and may not be running. Click here to view container statuses."
I waited, restarted but still getting the same error.
Should I have done something in Azure before doing your tutorial. It's my first time using Azure and I'm really confuse on how to fix this error
Hey! Glad you liked it :) Sometimes you get weird errors like that for all kinds of reasons. From my experience usually deleting the resource and creating it again can help solve the problem.
@@rowan-lea Thank you very much, I'm going to try again :)
step on Azure that free or not sir ?
and necessary to use with Dockerfile ?
You don't need to do the Azure parts, you can run it locally or find another host. As for the dockerfile I'm not entire sure, I don't do much docker development that doesn't use it. Perhaps a docker compose file could work, but I'm not sure if that's a direct replacement or something you need on top of a dockerfile.
What will the pricing for this?
Container registery and container instance?
Is it too costly compare to virtual machines?
From my experience, and stuff I've been playing with recently, in GBP the cost of the services combined, for a basic app like this, would be about £35-£40 a month, provided it was running.
From my experience containers would typically be cheaper to run than VMs (that's kind of the point, small and more lightweight), however the Azure pricing pages don't really seem to support that theory strongly:
azure.microsoft.com/en-gb/pricing/details/virtual-machines/windows/
azure.microsoft.com/en-gb/pricing/details/container-instances/
I recently put out a video about ways you can check your pricing, so you might be able to figure it out from here:
ua-cam.com/video/gy0n_jt-Ato/v-deo.html
To add to this, I don't really like interacting Linux as an OS, but I would always choose it for my container OS because you don't have to pay the additional licensing fee that you do with Windows, and using a container means I don't have to touch it as an OS.
How to connect it with database?
So you probably want to make some kind of database service you can call when an endpoint gets hit. Really you could use any kind of database depending on your needs, because there's so many different types it would probably make sense to look for a Python video for your specific database implementation.
@@rowan-lea I'm also interested in this, would you be open to ever making an additional video that uses an example database?
@@andreww2528 actually this came up in conversation literally today, maybe I will!
Why did you go with a container vs Azure function? Containers look to be more expensive. What am I missing?
Hey John, both have completely different use cases really. Functions are for short lived processes, and are very specific in how they are programmed. Containers are typically longer lived, can have much more compute power, and are less tied to any particular technology (i.e. you could make an app in any language and easily move it to something like AWS if you wanted to).
This video isn't to determine which is best, that depends entirely on your use case :)
To add to that, typically you're right in terms of cost, running something native to a platform is nearly always cheaper from my experience, but that's not really a good reason to choose one technology over the other, unless you can completely ignore any other factors.
How can you add HTTP authentication to a Container App? I know we could add it at the application layer, but then we'd get billed for even unauthorized attempts..
This should solve your problem as it uses middleware before it gets to your app: learn.microsoft.com/en-us/azure/container-apps/authentication
@@rowan-lea From the diagram, won't I still be billed for any requests to the authentication middleware container? The box around both containers makes it seem like they're both running in my account.
@@DavidManouchehri I'm not sure if they do charge for that. Ultimately you're going to need some kind of control in the way to block the request, it could even be a firewall. Most of these things I would imagine will be a 1 off monthly cost rather than something you pay for per request. There may be another way but it's not something I have much information about sorry.
@@rowan-lea I did find out that APIM is Azure's solution, but it costs hundreds per year. 😅
We ended up using Google Cloud Run instead, since authenticating service-to-service requests is free. (AWS Lambdas can also authenticate service-to-service requests, but it's a bit of a pain to deploy Lambda containers compared to Clod Run.)
I really hate the way you chose to talk , but thanks for the video