Run Docker Containers on Azure App Services

Alberto De Natale
5 min readMay 1, 2019

--

When I was a fresh graduate, I remember being asked about the difference between SQL and a DBMS. I had spent a lot of time working with the former but I had no clue about how to work with the latter.

The cloud offers simple means to host websites without the developer needing to know how to configure a server. Translated, more time writing code and less in configuring servers.

Azure offers three options for hosting a website:

  • Azure App Services (and Azure Functions)
  • Virtual Machines
  • Service Fabrics

They support:

  • Multiple languages and frameworks, such as ASP.NET, ASP.NET Core, Java, Ruby, Node.js, PHP, or Python
  • They support background services running PowerShell and other scripts
  • They come with DevOps optimizations such as continuous integration, continuous deployment (optionally using Azure DevOps, GitHub, BitBucket, Docker Hub, or Azure Container Registry), test and staging environments
  • Global scale up or out. Microsoft’s global data center infrastructure spans around the entire globe. The servers come with a service level agreement currently set to a minimum of 99.95% of the time (not available for free or Shared tiers)
  • Connections to SaaS platforms (such as SAP, Salesforce), internet services (such as Facebook) and on-premises data (with Hybrid Connections and Azure Virtual Networks)
  • ISO, SOC, and PCI compliant
  • Social Logins (i.e. Microsoft, Google, Facebook, Twitter)
  • Application Templates, available in the Azure Marketplace, such as WordPress, Joomla, and Drupal
  • Integration with Visual Studio
  • API and Mobile Features such as CORS support, offline data sync, push notifications
  • Serverless code with Azure Functions

In the following steps, I will try to deploy a sample .NET Core website on a Docker container running on an Azure App Service.

What will be done is:

  1. Create a resource group
  2. Create an Azure Container Registry
  3. Create a sample .NET Core website
  4. Create an Azure App Service running the container

Create a Resource Group

A resource group is a container that holds related resources on Azure. They improve control of related resources.

  • Resources share the same lifecycle of their group
  • Each resource only exist in one group
  • Resources can be added or removed to a resource group at any time
  • Resources can be moved from one resource group to another
  • Resource groups can contain resources that reside in different regions
  • Resources can interact with resources in other resource groups

Your resource group will be available under the resource groups section:

Create an Azure Registry Container

A registry container will store your docker images, published using the Docker CLI.

Enable an admin used and take note of username and password. The will be needed to log in from the docker CLI.

Install Docker On your local machine

You will need to download Docker Desktop in order to user the Docker CLI.

This will require you to log out from your session:

After restarting, you will be prompted to enable Hiper-V and containerization for your Windows machine. Once that is done, you will be able to login in your Docker Desktop.

In order to test your installation, open a command prompt as Administrator and run

docker run -it hello-world

Login on your Azure Registry by running:

docker login deployanappservice.azurecr.io

Create a sample .NET Core web application

Always within the wizard, enable docker support:

On start, Visual Studio will automatically run scripts that will verify that your Desktop is running Docker and it will try to pull an image that will be used to deploy your website. The default image used by visual studio 2019 (Version 16.0.2) is the “aspenet:2.1-stretch-slim”.

The new project will come already with a working Dockerfile that should be fine.

Deploy your image on the Azure Container Registry

From the “Web Publish Activity” windows you will be able to monitor the publish progress. It will take some time for Docker to download all the required images.

Docker running the provided Dockerfile

At the end of the publish you will be able to see the image on your Azure Container Registry.

Create a Docker Image running on an App Service (currently in preview)

  1. Create a new Resource Group,

2. Resource name, publish type, Operating System and location

3. Pricing

There is a free tier available for code publish method.

However, the most basic plan available for Docker containers is not free.

On the Docker tab, you will be able to pass the references to you just deployed image.

Fill the Startup Command with the last line you will find in your Visual Studio Dockerfile. In my case that will be:

Run your webapp

--

--

Alberto De Natale
Alberto De Natale

Written by Alberto De Natale

Alberto De Natale is a passionate tech-enthusiast software developer.

No responses yet