Easy Docker App Deployment with Azure

Simple, robust deployment of “Dockerized” applications with Azure Container Registry and Instances through the Docker CLI

Bobby Neelon
Coach Neelon
6 min readOct 16, 2020

--

TL;DR

The Docker CLI, in conjunction with Azure Container Registry and Azure Container Instances, makes containerized app deployment a breeze.

Background

I had to write a custom alert/webhook integration between Grafana and Slack for a client (maybe it’s own article?!). After writing the Python Flask app, I had do decide how we wanted to deploy it. I’ve used AWS quite a bit, but my client already had an Azure account. While I was not very familiar with Azure and had limited Docker experience, my experience deploying the application was refreshingly pleasant and straightforward. Below, I’ll provide a very simple example of the workflow.

The App

The scope of this article is not to write a Flask app or to teach you how to “Dockerize” an application. Once you’ve gained that requisite knowledge, and if you’d like to reproduce my workflow, you can clone the app, dockerfile, and requirements.txt used in this example from my GitHub repo.

It is also assumed you’ve set up an Azure account. When you first sign up, you get $200 in free credits to play with, and they do have a free tier for many commonly used services.

The core Flask app is below. Pretty straightforward. It takes a POST request, and returns the JSON body of that request back to the sender in a little message.

One thing to take note of is that we are serving it on Port 80. That will come into play later as Azure Container Instances do not allow for port mapping like a local Docker deployment does.

Create Azure Container Registry

Azure Container Registry(ACR) is a service to house your container images. Sign into https://portal.azure.com. Then, search for Azure Container Registry, or go to this link to create a registry.

Once you’re there, fill out the info similar to how I have in the image below, and select the Review + Create button.

I chose the South Central Region as I’m in Texas, but any available region should suffice. You can choose to go on to the Networking/Encryption/Tags sections, but at my subscription level, options in the former 2 are greyed out, and for simplicity, I wont add any tags(though that is a best practice).

ACR Access Keys

Once the registry is deployed and Azure confirms that it’s complete, you can go to the resource home page. Along the left panel, under Settings, you’ll find an Access Keys button. Let’s head there.

Container Registry Home Page

Once there, make sure Admin user toggle is “Enabled” and take note of the various fields including Username and Password(s). You’ll need those for the next steps in the Docker CLI.

Docker CLI

If you’ve used Docker, I’m sure you’re familiar with the common CLI functions. What is really handy is their integration with Azure. You’ll see below how simple it can be!

One nice thing that Azure offers in the Registry Home Page is a Quick start guide(see below). Just cd into your app directory and run the steps included but referencing your Docker image name instead of hello-world.

I will show you my personal steps below:

  1. cd into your app directory.
  2. Run docker login <your Login server> and enter your Username and Password in the prompts that follow. If you do it correctly, it should return Login Succeeded.

3. Run docker tag <your Docker image name> <your Login server>/<your Docker image name>.

4. Run docker push <your Login server>/<your Docker image name>. This may take some time as it is pushing the full image up to Azure.

5. As a check, run docker pull <your Login server>/<your Docker image name> to ensure the image is up to date in ACR.

Create Azure Container Instance

Azure Container Instances(ACI) is a service to host your containerized services very affordably and robustly. You can search the portal for it or create an instance using this link.

Once there, you can fill out the first page as I have below. Again, take note of the Region. The big piece here is to select Azure Container Registry from Image source and then choose the Registry and Image we created in our previous steps. From there, let’s move onto Networking.

In the Networking tab, you can specify the DNS name label for your instance. Also, you can specify certain ports if you’d like. Notice port 80 open for TCP traffic matches our Flask App. As mentioned earlier, ACI does not support port mapping.

If you have any Environmental Variables, you’ll want to move onto the Advanced tab, but since our app is super simple, we’ll skip right to Review + Create.

At this point, Azure will deploy the resources and let you know once it is up and running.

Testing the Endpoint

To test my deployment, I used Postman. As you can see, the app took the JSON Body I sent and returned it in a message. Voila!

What if My Code Changes?

If you’re code changes, you’ll just need to rebuild the image and then go through the same steps we did earlier:

  • Within ACR, login, tag, and push.
  • Within ACI, Restart the instance to apply the changes from ACR.

Future Enhancements

To make this more robust going forward there are a few things I’d like to do.

Pricing

For ACR, the Basic Tier is $5 per month ($20 for the Standard Tier that we selected — going to have to change that!) See the screenshot below of the Azure Pricing Calculator.

ACI is billed per compute-second. I’m sure at scale or for long running jobs, it could become costly, but for low usage, simple apps, it’s practically free. See this link for more details: https://azure.microsoft.com/en-us/pricing/details/container-instances/.

Conclusion

As you can see, Azure + Docker make it very easy to deploy containerized applications. Going forward, I may try to replicate this process in AWS and Google Cloud Platform to compare functionality. Stay tuned!

--

--

Bobby Neelon
Coach Neelon

Data Analytics Professional, Cloud Enthusiast, Sports Nerd