image
Running a Container on Azure App Service

Contents

Running Containers on Azure App Service
Running a Container on Azure App Service
Difficulty
Intermediate
Duration
10m
Students
1339
Ratings
4.9/5
starstarstarstarstar-half
Description

Although Azure App Service supports many different programming languages and frameworks, such as .NET, Java, and Python, sometimes you might need a different development stack that isn’t directly supported by App Service. In these cases, the solution is to create a custom Docker container that has all of the software you need preinstalled. In this course, we’ll give you a demonstration of how to build and run a Docker container on Azure App Service.

Learning Objectives

  • Build and run a Docker container on Azure App Service

Intended Audience

  • Anyone who wants to run an unsupported development stack on Azure App Service

Prerequisites

 

Transcript

Welcome to “Running a Container on Azure App Service”. To get the most from this course, you should already have some basic experience using App Service. If you don’t, then you can take our “Introduction to Azure App Service” course.

In this course, I’ll give you a demonstration of how to build and run a Docker container on App Service. If you want to do the demo yourself, as well, then you’ll need to have an Azure account. If you don’t already have one, then you can create a free trial account.

Although App Service supports many different programming languages and frameworks, such as .NET, Java, and Python, sometimes you might need a different development stack that isn’t directly supported by App Service. In these cases, the solution is to create a custom Docker container that has all of the software you need preinstalled.

A Docker container is a self-contained software environment that includes an application and all of its dependencies. Because it includes everything it needs, the container is portable. That is, it can run on any system that supports Docker without having to worry about what’s installed in the underlying operating system.

Container images are normally stored in a central location, which makes it easier to manage them and deploy them. Microsoft offers a service called Azure Container Registry that provides this central location.

To deploy a container to App Service, here are the steps you need to take. First, create an instance of Azure Container Registry. Then build a container image. Next, upload it to your container registry. Then deploy it from the container registry to Azure App Service. And finally, try to connect to the application to make sure it worked.

Okay, let’s go through the steps. First, we’ll create the container registry. In the Azure Portal, type “container” in the search bar, and choose “Container registries”. Then click “Create”. We can choose an existing resource group, but let’s create a new one, which will make it easier to delete everything when we’re done. I’ll call it “demorg”.

The registry name has to be unique across all Azure customers, so I’ll call it “ca” for “Cloud Academy” and then “reg”. You’ll have to choose a different name if you do this yourself. For the SKU, choose “Basic”, which is cheaper. Then click “Review + Create” and “Create”.

When it’s done, click “Go to resource”. Then go to “Access keys” and set “Admin user” to “Enabled”. This is required for deploying to App Service.

Next, we need to build the container image, so you need to have Docker installed and running on your desktop. If you don’t already have it, then you can download it from docs.docker.com/get-docker.

Once you have Docker running, you can build the container image in a variety of different ways, but we’re going to do it from Visual Studio Code, which is a free development tool from Microsoft. You can download it from code.visualstudio.com.

You’ll also need to install the Azure Tools extension. To install it, click on Extensions, search for “azure”, and install Azure Tools. When it’s done, the Azure logo and the Docker logo will show up over here.

Click the Azure logo, then click “Sign in to Azure”. It’ll bring up a browser tab where you have to select your Microsoft account. This came up on a different screen for me, which is why you can’t see it. Okay, I selected my account, so I’m logged in.

Now we need to connect to Azure Container Registry. Click the Docker logo. Then click “Connect Registry”, and select “Azure”.

Next, we need to create a Dockerfile, which is a file that tells Docker how to build a specific container. Normally, we’d need to type some instructions that tell Docker what base image to use and how to install our application and all of its dependencies, but this isn’t a Docker course, so we’re going to take a shortcut. We’re just going to copy an example container image that Microsoft has already created.

Click on the “Explorer” icon. Then click “Open Folder”, and create a new folder called “dockerdemo”. Now click “New File”. To save you the trouble of typing in the contents of this file, I’ve put the text in a readme file in a GitHub repository. You can find a link to the repository at the bottom of the Overview tab below this video. Copy this text, paste it into the editor, and save it. Call it “Dockerfile”.

These instructions tell Docker to get a .NET Core container image from the Microsoft Container Registry, which is Microsoft’s own registry. The last line tells Docker where the app is in the container, so it can start it when it runs the container.

Now we’re going to build the container image. Hit the F1 key. Then type “docker images”, and select “Build image”. This is what we want to name the image plus the tag to apply to it. We need to tell it that we’re going to put this image in our container registry, so we need to prefix this with the URL of the container registry. I called mine “careg”. Then type “.azurecr.io” because that’s where Azure Container Registry hosts it. Then slash and the name of the image. Then leave the tag as “latest” which means that this is the latest version of the container.

Okay, it’s done. Now we’re going to push the image to the container registry. Click the Docker logo. The image name shows up here. If you click on it, the “latest” tag appears, which means this is the version of the image that we just built. Now, right-click on the image and select “Push”. It brings up the image name and tag again up here, so hit “Enter”. It takes quite a while to push the image to the registry, so I’ll fast-forward.

All right, it’s done. To check that it worked, click the Refresh button next to “Registries”, and the image name should show up under your registry. If you click on it, the tagged version of the image is there.

Now that the container image is in our registry, we can finally deploy it to Azure App Service. Right-click the tagged image, and select “Deploy image to Azure App Service”. Choose a globally unique name for the app. I’m going to use “ca” and the “dockerdemo”. You’ll have to choose something else. Then select the resource group you created before. I called mine “demorg”. Then select a region.

Finally, select an App Service Plan. If you haven’t created one already, then you can create one from here. The pricing tier for your service plan has to be at least Basic because you can’t deploy a container to a Free plan.

If you have an App Service Plan and it’s not showing up here, it might be because it’s for the wrong operating system. This Docker image runs on Linux, so you can only select a Linux App Service Plan. It’s possible to deploy a Windows container to App Service, but most people use Linux.

Now, it’s pulling the image from the container registry and deploying it to the App Service Plan. Okay, it’s finished. Now we can make sure it worked by clicking “Open Site”. If you need to do this after the popup disappears, you can click on the Azure logo. Here’s the app we just pushed to App Service in a container. If you right-click, you can select “Browse Website”. It came up on my other monitor, so I’ll bring it over. It opened the URL of the app we just deployed on App Service. This is Microsoft’s sample app, so it worked.

That’s the end of this demo. If you want to avoid incurring any additional charges, then the easiest way to delete everything is to delete the resource group you created. I’ll do that with my demorg resource group.

And that’s it for running a container on Azure App Service. Please give this course a rating, and if you have any questions or comments, please let us know. Thanks!

About the Author
Students
203044
Courses
97
Learning Paths
164

Guy launched his first training website in 1995 and he's been helping people learn IT technologies ever since. He has been a sysadmin, instructor, sales engineer, IT manager, and entrepreneur. In his most recent venture, he founded and led a cloud-based training infrastructure company that provided virtual labs for some of the largest software vendors in the world. Guy’s passion is making complex technology easy to understand. His activities outside of work have included riding an elephant and skydiving (although not at the same time).