Deploy flask application on Azure app service using your own domain
Published: October 31, 2018
Last updated: November 1, 2018
In this post I want to describe the 3 steps to make your flask app (hello world) and have it deployed on Azure and
accessible via your own domain / website. Although it is a static hello world application that will be created,
I think it is interesting as in a later stage this can be applied on machine learning or natural language
processing apps. They will typically require an app engine.
It is good to have discipline in respecting some ground rules: installing Flask in a virtual
environment, work with a seperate project folder each time and upgrading to the required Python
version. These best practices save some time and frustration afterwards.
For Python I work with an Anaconda distribution.
First hello world can be copy-pasted from above mentioned tutorial. Try to understand what it means.
Deploy it to Azure as an application
So you have a hello world running on localhost but want to make it publically accessible? On the
flask website you will see a
list of options for (cloud) deployment.
I chose for Azure for this post. Main reason is the ease of deployment. Azure offers an out of the box
container with the recommended Python version for flask pre-installed (being 3.7 at the time of writing).
Steps to be
taken can be found here.
You should of course have an Azure login.
You will be prompted to choose for an Azure cloud shell.
In case you don't have a storage account yet, you will be required to create it here.
There is a free trial for 12 months. The steps to do so are self-explanatory. The shell will startup once
storage account is created.
From here you need to create your deployment user, user group and
app service plan. Simple copy pasting the code in above-mentioned tutorail in the Azure shell
is sufficient.
Setup of a local git directory is required (so NOT in the azure shell but in your local cmd):
cd "localdirpath"
git --bare init (in case you are not storing the repository on github)
git add .
git commit -m 'message'
The app is now deployed and has a unique endpoint containing the name of your app you chose in the steps above.
Link the app to your own domain
The minimal monthly cost of above Azure deployment is 32€ per month (European region). You will get by
default one month free trial. Anyhow if you want to deploy to your own domainname - which I want towards
www.nlpit.be/hello - you need a paying app service plan. The free tier is not supported.
Again a clear tutorial will guide you through.
You will need to link the unique app endpoint in the DNS configuration portal of the domain provider.
Whilst adding the domainname in Azure. The tutorial warns for a domain ownership issue as in the
printscreen (right below - red exclamation mark). This can be due to a typo. On the other hand, DNS propagation takes a while.
So if it doesn’t work immediately, don’t panic. Wait for some hours and try again to add the hostname.
For me the propagation was done after 15 minutes.
The app is now deployed and coupled to your own domain name / website.