Skip to content
Permalink
Browse files

deploy

  • Loading branch information...
mbcrump committed Aug 11, 2019
1 parent bab8db7 commit 53e5d94e4204bc26b50dcb645005f785442a631b
Showing with 105 additions and 2 deletions.
  1. BIN .DS_Store
  2. +2 −2 .vuepress/config.js
  3. BIN .vuepress/public/.DS_Store
  4. +103 −0 blog/tip216.md
BIN +0 Bytes (100%) .DS_Store
Binary file not shown.
@@ -32,12 +32,12 @@ module.exports = {
{
title: 'Recently Added',
collapsable: false,
children: ['/blog/tip215','/blog/tip214','/blog/tip213','/blog/tip212','/blog/tip211','/blog/tip210','/blog/tip209','/blog/tip208','/blog/tip207', '/blog/tip206','/blog/tip205','/blog/tip204','/blog/tip203','/blog/tip202','/blog/tip201']
children: ['/blog/tip216','/blog/tip215','/blog/tip214','/blog/tip213','/blog/tip212','/blog/tip211','/blog/tip210','/blog/tip209','/blog/tip208','/blog/tip207', '/blog/tip206','/blog/tip205','/blog/tip204','/blog/tip203','/blog/tip202','/blog/tip201']
},
{
title: 'App Service',
collapsable: true,
children: ['/blog/tip208','/blog/tip16', '/blog/tip20', '/blog/tip21', '/blog/tip22', '/blog/tip23', '/blog/tip26', '/blog/tip27', '/blog/tip28', '/blog/tip29', '/blog/tip30', '/blog/tip31', '/blog/tip32', '/blog/tip33',
children: ['/blog/tip216','/blog/tip208','/blog/tip16', '/blog/tip20', '/blog/tip21', '/blog/tip22', '/blog/tip23', '/blog/tip26', '/blog/tip27', '/blog/tip28', '/blog/tip29', '/blog/tip30', '/blog/tip31', '/blog/tip32', '/blog/tip33',
'/blog/tip101', '/blog/tip102', '/blog/tip103', '/blog/tip104', '/blog/tip105', '/blog/tip107', '/blog/tip108', '/blog/tip109', '/blog/tip110',
'/blog/tip112', '/blog/tip113', '/blog/tip117', '/blog/tip119', '/blog/tip132', '/blog/tip143',
'/blog/tip144', '/blog/tip149', '/blog/tip184']
BIN +0 Bytes (100%) .vuepress/public/.DS_Store
Binary file not shown.
@@ -0,0 +1,103 @@
---
type: post
title: "Tip 216 - How to deploy ASP.NET application to Docker Hub and Azure"
excerpt: "Learn how to use create a custom container image and deploy that to Azure App Service"
tags: [azure, containers, ASP.NET, app service]
share: true
date: 2019-08-11 02:00:00
---

::: tip

:tv: Watch the video : [How to deploy ASP.NET application to Docker Hub and Azure](https://www.youtube.com/watch?v=pRRcQpp90F8&list=PLLasX02E8BPCNCK8Thcxu-Y-XcBUbhFWC&index=66&t=0s?WT.mc_id=youtube-azuredevtips-micrum).

:bulb: Learn more : [Azure App Service Web App for Containers](https://azure.microsoft.com/services/app-service/containers?WT.mc_id=azure-azuredevtips-micrum)

:::

#### How to deploy ASP.NET application to Docker Hub and Azure

Running your application in a container is a great way to make sure that it can run anywhere and that its environment is the same, regardless of where you run it. You can run almost any type of application in a container and you can run containers almost anywhere. Azure has a lot of options for running containerized applications. One of those is [Azure App Service Web App for Containers](https://azure.microsoft.com/services/app-service/containers?WT.mc_id=azure-azuredevtips-micrum). This is a service that can run a container on the App Service platform, which gives you some of the PaaS features like deployment slots and easy authentication. Let's take a look at how to containerize an ASP.NET Core application with Visual Studio and host it in Docker Hub. And then let's take a look at how to deploy that container to Web Apps for Containers and run it in Azure.

#### 1. Taking care of the prerequisites

Before you get started, you need to make sure that you have all of the prerequisites to follow along.

1. You'll need the latest version of Visual Studio 2019 with the Azure and .NET Core workloads installed
2. You need Docker on your PC to develop container-based applications. Download it [here](https://store.docker.com/editions/community/docker-ce-desktop-windows)
3. For hosting a container image on Docker Hub, you need a [Docker Hub](https://hub.docker.com) account

#### 2. Containerize an ASP.NET Core application and host the image in Docker Hub

We'll create a new ASP.NET Core web application and make sure that it can run in a Windows container. Once we've created this, we'll host the container image in Docker Hub so that we can use it later in Azure.

1. in Visual Studio, create an ASP.NET Core application. You can do that by using **File > New > Project** and selecting the **ASP.NET Core Web Application** template. In the screen that follows, choose the **Web Application (Model-View-Controller)** option and leave the **Enable Docker Support** checkbox unchecked
2. Once the application is created, go to the solution explorer and **right-click** on the project and choose **Add > Docker Support**

<img :src="$withBase('/files/AddDockerSupport.png')">

(Add Docker support in Visual Studio)

3. Choose **Windows** as the Target OS and click **OK**
4. In the Docker file, change the **From as base** and **FROM a build** lines to

```
FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016 AS base
FROM microsoft/dotnet:2.1-sdk-nanoserver-sac2016 AS build
```
These images are for .NET Core 2.1, but you can also use images for later versions of .NET Core.

5. Build the project
6. From the solution explorer, **right-click** the project file and click **Publish**
7. Choose **Container Registry** as the publish target
8. Select **Docker Hub** and click **publish**

<img :src="$withBase('/files/PublishToDockerHub.png')">

(Publish to Docker Hub from Visual Studio)

8. Fill in the **credentials** to Docker Hub. Your username should be a username that's not an email address
9. Now click **publish** to push the image to Docker Hub

You should now be able to see the container image in Docker Hub.

<img :src="$withBase('/files/ImageInDockerHub.png')">

(Container image in Docker Hub)

#### 3. Run the container image in Azure App Service Web Apps for Containers

Now that we have a container in Docker Hub, we can run it in Azure App Service Web Apps for Containers.

1. First, create a new Web Apps for Containers. In the Azure portal, click the **"Create a resource"** button and search for **"Web Apps for Containers"**
2. Click on **Web Apps for Containers** in the search results and click **Create**

<img :src="$withBase('/files/CreateWebApp.png')">

(Create Web App blade in the Azure portal)

3. Fill in a **Name**
4. Pick or create the **Resource group**
5. Leave the OS to **Windows**
6. And click on **Configure container**

<img :src="$withBase('/files/ConfigureContainer.png')">

(Configure container blade in the Azure portal)

7. In the **Configure container** blade, pick **Single container** and pick **Docker Hub**
8. Now type in the name to the image that we've just published including the tag. This should be something like **azuremichael/containertricks:latest** and click **OK**
9. Click **Create** to create the Web App. Once the Web App is created, it will spin up the container. This can take a while.
10. In the Web App overview blade in the Azure portal, you will find the **URL** to the Web App. Click on it to open the application. If it's not working, you should wait a few minutes for the container to initialize and try again

<img :src="$withBase('/files/RunTheApp.png')">

(Application running in a browser)

You can now use the application, which is running in a Windows container in Azure Web Apps for Containers.

#### Conclusion

Visual Studio makes it very easy to containerize applications and publish them. Once published, it is very easy to use a container image in a service like Azure App Service Web Apps for Containers. And the cool thing is that the app runs in a container, even when it is running in Azure. This means that it is the exact same thing that you run locally. So if it runs locally it will also run in Azure.
Also, Web Apps for Containers comes with some cool features, like the ability to use deployment slots, which means that you can publish a new version of your app in a slot and test it. And once you are ready, you can swap the slot into production with almost no downtime. And, as you saw in this post, you can use Windows containers in Web Apps for Containers. You can also use Linux containers if you want. Go and check it out!

0 comments on commit 53e5d94

Please sign in to comment.
You can’t perform that action at this time.