>> Learn how to deploy an ASP.NET app
in a Windows image to Docker Hub,
from Visual Studio and run it in
Azure App Service in this episode of Azure tips and tricks.
Before we can create a Docker container,
we need to install Docker for Windows.
This is also available for Mac and Linux.
You can download and run the installation file from here,
and you do need to be logged in with a Docker Hub account.
So, if you don't have one yet,
you need to create one on this website.
During the installation, it will ask you if you want to
use Windows Containers instead of Linux ones.
Check the box as we'll be using Windows Containers in our demo.
You can also change this later in the Docker settings.
Once it is installed,
restart your computer to make sure everything is working okay.
I'll skip ahead to when it is installed. All right.
Let's create the app.
I'm in Visual Studio and I have the.NET Core workload installed.
You can check if you have that
installed in the Visual Studio Installer.
Let's create a new project.
I'll do "File", "New Project",
and I'll choose an "ASP.NET" Core project.
Let me give it a name and "Okay".
All right? I will leave this as this.
I'll also leave the Docker Support unchecked,
because I want to show you how to add
this in an already existing project.
All right. Let's create it.
There it is. Now, for the magic,
I'll right-click on the project file and
choose "Add Docker support",
and I want to use "Windows containers".
Okay. That's it.
We now have a Docker file in the project.
This file contains the container configuration.
It uses operating system images to build
the container and run the application in it.
Let me change these images slightly.
These images are for the Windows Server
2016 64-bit Nano Server OS.
To run this app,
you can use whatever images you like that can run ASP.NET Core.
All right. Let's see if this builds, and it does.
Now, let's publish the container.
I'll right-click the project again and choose "Publish".
Now, I choose "Container Registry" and "Docker Hub"
as I want to put the Container on Docker Hub. All right.
Here, fill in your Docker Hub username and password.
Your username is not an e-mail address.
You'll see your username when
you sign in to the Docker Hub website.
That's it. Let's publish it.
This can take awhile, so I'll skip to when it's done.
Here we go. We are signed in to the Docker Hub website.
This is a container image that we've
just published from Visual Studio.
Here, we can see that Visual Studio added
a tag that says latest to the image.
You can use tags for versioning and identification.
So, let's run this Container.
I'll switch to the Azure portal.
From here, I'll create a new web app for Containers.
This is a web app like the Standard App Services web
app that runs Containers
instead of running an application directly.
Let's create one. Let's fill this in.
First, I need to fill in a name.
Next, I'll choose my existing resource group.
Now, for the container.
Here, I can choose where the Container comes from.
I need to choose Docker Hub as that is where my Container is.
Here, I typed the container name like this.
I also need to add the tag which is latest.
That's it, that is all that we need to do.
I will created and skip ahead to when it's done.
Here we go. This is the web app for containers,
and it is running our container with
the ASP.NET Core application in it.
Let's go to its URL and see if it works.
Yep. There it is,
running in a container.
Adding container support to
an application is really simple from Visual Studio.
From there, you can easily publish it to Docker Hub or any other
Container Registry and run it in Azure. Go check it out.