Scott Hanselman

Penny Pinching in the Cloud: Deploying Containers cheaply to Azure

June 16, 2018 Comment on this post [8] Posted in Azure
Sponsored By

imageI saw a tweet from a person on Twitter who wanted to know the easiest and cheapest way to get an Web Application that's in a Docker Container up to Azure. There's a few ways and it depends on your use case.

Some apps aren't web apps at all, of course, and just start up in a stateless container, do some work, then exit. For a container like that, you'll want to use Azure Container Instances. I did a show and demo on this for Azure Friday.

Azure Container Instances

Using the latest Azure CLI  (command line interface - it works on any platform), I just do these commands to start up a container quickly. Billing is per-second. Shut it down and you stop paying. Get in, get out.

Tip: If you don't want to install anything, just go to https://shell.azure.com to get a bash shell and you can do these command there, even on a Chromebook.

I'll make a "resource group" (just a label to hold stuff, so I can delete it en masse later). Then "az container create" with the image. Note that that's a public image from Docker Hub, but I can also use a private Container Registry or a private one in Azure. More on that in a second.

Anyway, make a group (or use an existing one), create a container, and then either hit the IP I get back or I can query for (or guess) the full name. It's usually dns=name-label.location.azurecontainer.io.

> az group create --name someContainers --location westus
Location Name
---------- --------------
westus someContainers
> az container create --resource-group someContainers --name fancypantscontainer --image microsoft/aci-helloworl
d --dns-name-label fancy-container-demo --ports 80
Name ResourceGroup ProvisioningState Image IP:ports CPU/Memory OsType Location
------------------- --------------- ------------------- ------------------------ ---------------- --------------- -------- ----------
fancypantscontainer someContainers Pending microsoft/aci-helloworld 40.112.167.31:80 1.0 core/1.5 gb Linux westus
> az container show --resource-group someContainers --name fancypantscontainer --query "{FQDN:ipAddress.fqdn,ProvisioningState:provisioningState}" --out table
FQDN ProvisioningState
--------------------------------------------- -------------------
fancy-container-demo.westus.azurecontainer.io Succeeded

Boom, container in the cloud, visible externally (if I want) and per-second billing. Since I made and named a resource group, I can delete everything in that group (and stop billing) easily:

> az group delete -g someContainers 

This is cool because I can basically run Linux or Windows Containers in a "serverless" way. Meaning I don't have to think about VMs and I can get automatic, elastic scale if I like.

Azure Web Apps for Containers

ACI is great for lots of containers quickly, for bringing containers up and down, but I like my long-running web apps in Azure Web Apps for Containers. I run 19 Azure Web Apps today via things like Git/GitHub Deploy, publish from VS, or CI/CD from VSTS.

Azure Web Apps for Containers is the same idea, except I'm deploying containers directly. I can do a Single Container easily or use Docker Compose for multiple.

I wanted to show how easy it was to set this up so I did a video (cold, one take, no rehearsal, real accounts, real app) and put it on YouTube. It explains "How to Deploy Containers cheaply to Azure" in 21 minutes. It could have been shorter, but I also wanted to show how you can deploy from both Docker Hub (public) or from your own private Azure Container Registry.

I did all the work from the command line using Docker commands where I just pushed to my internal registry!

> docker login hanselregistry.azurecr.io
> docker build -t hanselregistry.azurecr.io/podcast .
> docker push hanselregistry.azurecr.io/podcast

Took minutes to get my podcast site running on Azure in Web Apps for Containers. And again - this is the penny pinching part - keep control of the App Service Plan (the VM underneath the App Service) and use the smallest one you can and pack the containers in tight.

Watch the video, and note when I get to the part where I add create an "App Service Plan." Again, that's the VM under a Web App/App Service. I have 19 smallish websites inside a Small (sometime a Medium, I can scale it whenever) App Service. You should be able to fit 3-4 decent sites in small ones depending on memory and CPU characteristics of the site.

Click Pricing Plan and you'll get here:

Recommend Pricing tiers have many choices

Be sure to explore the Dev/Test tab on the left as well. When you're making a non-container-based App Service you'll see F1 and D1 for Free and Shared. Both are fine for small websites, demos, hosting your github projects, etc.

Free, Shared, or Basic Infrastructure

If you back up and select Docker as the "OS"...

Windows, Linux, or Docker

Again check out Dev/Test for less demanding workloads and note B1 - Basic.

B1 is $32.74

The first B1 is free for 30 days! Good to kick the tires. Then as of the timing of this post it's US$32.74 (Check pricing for different regions and currencies) but has nearly 2 gigs of RAM. I can run several containers in there.

Just watch your memory and CPU and pack them in. Again, more money means better perf, but the original ask here was how to save money.

Low CPU and 40% memory

To sum up, ACI is great for per-second billing and spinning up n containers programmatically and getting out fast) and App Service for Containers is an easy way to deploy your Dockerized apps. Hope this helps.


Sponsor: Check out dotMemory Unit, a free unit testing framework for fighting all kinds of memory issues in your code. Extend your unit testing with the functionality of a memory profiler.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
June 16, 2018 17:41
Docker seems so great when you talk about it. It just doesn't do what I want.

What I want is to containerize desktop apps that have GUIs. Say, I have a couple of apps that need Java SE. I wish I could install them in their own containers along with a copy of Java Runtime. Or... wouldn't it be great to run old apps that rely on an older version of QuickTime in a container, so that QuickTime does not desecrate the whole system? All the file-association-stealing would go away.
June 16, 2018 20:24
Fleet Command: you can run vnc server in same container as your app if you need. A lot of samples exists.

About beating Azure cheap price containers: I am running my containers in managed k8s based on Google preemptible instances.

I don't know Azure alternative for this pricing.
June 16, 2018 21:03
I could not find any info about joining them to a domain (AD). Is it possible/usually done? Thanks!
June 17, 2018 18:38
I have always had this unconfirmed feeling that Azure prefers that you to use a production resource to serve your production app, and that if you use a dev/test resource to serve your production app, they will take down your site or frown on you when you call support and call you a cheapskate.

What do you think Scott? Am I being paranoid?
June 17, 2018 20:05
Fleet Command, the Desktop Bridge works the way you have described. When you package an application, you can include a special folder called VFS which is a virtualization of the systems folder. The packaged app will look for dependencies first in its VFS folder and only later in the system. This way, you can embed old dependencies or different runtime versions without having to install them system wide. More info herehttps://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-behind-the-scenes
June 19, 2018 14:16
Thanks Scott for an useful post as usual. When I check my Azure plan, I cannot see F1 or D1 tiers. Any idea?
June 19, 2018 19:58
Great post and video.

I've been putting into production Wordpress sites using Azure Kubernetes Service, and gave Azure Web Apps for Containers a try inspired by your article. It was exciting to see Docker Compose and Kubernetes supported (beta) in Azure Web Apps for Containers.

https://davemateer.com/wordpress/2018/06/18/Web-App-for-Windows-Linux-Docker.html

I found that performance can be an issue if your workload needs fast disk access as it is using Azure Files (and not the faster Azure attached Disk). I wrote about this https://davemateer.com/wordpress/2018/05/29/Wordpress-Persistence-AKS.html

So I'm sticking with AKS currently.

It was an enjoyable experience trying out Azure Web Apps for Containers!
June 22, 2018 22:33
So I'm sticking with AKS currently.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.