Deploy ASP.NET Core App as Azure Containers Instances (ACI)

Microsoft has invested billions in Azure to drive technology and also hired best of the minds on this planet. From last few months, Azure has been launching new container-focused products and services on a regular basis. One of these products is Azure Container Instances. It acts as a bridge between platform as a service and infrastructure as a service architecture. Perhaps it would be okay to call this service as “Container as a Service”. Azure Container Instances (ACI) allows to rapidly create and launch containerized applications, without any overhead and with an easily scriptable set of commands. Designed to work both on its own and with tools like Kubernetes, ACI adds container-management commands to Azure, coupling them with a billing model that’s based on per-second usage, with no need to create and deploy (and pay for) container hosts. In this blog post, we’ll create an ASP.NET Core App, containerize it and deploy it as single instance on ACI.  

Create a ASP.NET Core Web App

We’ll be creating this using Visual Studio 2017. Open Visual Studio and go to file -> new -> project and Select an ASP.NET Core Web App project:

Create an core web app project using Visual Studio

Provide a name for the project and path to store files. In our example, this would be the DemoWebAppProject and then click Ok. After this, out of the templates provided by Visual Studio, select “Web Application Template”:

Select web application template and core version

Select appropriate dotnet version. Also uncheck the option for “Enable Docker Support”. Click Ok and it will create a very basic web app project based on dotnet core version.

Go ahead and build the project and it should build fine.

Create Docker Image

We’ll need to go to root project path and add a basic Dockerfile to it. After this, open the file in Visual Studio and type below code:

FROM microsoft/aspnetcore:latest
WORKDIR dockerdemo
ADD ./DemoWebAppProject/Debug .
ENTRYPOINT ["dotnet", "DemoWebAppProject.dll"]

Create the dockerfile for the project

After this, save the Dockerfile. By default, if you do not expose a port and bind the application to it, ASP.NET image will expose port 80 and bind the application to it.

Build a Docker Image

We need to open command prompt in admin mode or PowerShell in admin mode and browse to the project root directory. After this, we can run below command to create a docker image:

docker build -t aspnetcore/demowebapp: .

Create docker image for web app

Verify that image has been built fine using docker images command. We can also initiate a container to make sure that our image is working fine as expected:

docker run -d -p 8086:8086 -name=demowebapp aspnetcore/demowebapp:

Initiate a container from the docker image created

And browsing the application in a browser:

Verify that application is working fine inside container

Push the image to the Azure Container Registry

For deploying docker image, first we need to push it to a container registry. For this post’s purposes, we’ll be using ACR or Azure Container Registry. First we need to login to ACR using below command:

docker login -u {username} -p {password} {ACR-name}

Now, we need to tag our image again so that ACR can accept it. For this, our image tag needs to be first accompanied by ACR name:

docker tag aspnetcore/demowebapp:

After this, we can push docker image using:

docker push

Tag and Push docker image to a registry

Deploy Dockerized Image as Azure Container Instance

Open Azure Portal, select ACR in reference and then go to Registries. You should be able to find the uploaded docker image here. Click on the image and then click on the ‘Run instance’ option:

Select deploy to instance from docker repo

Now, submit the details for the instance to be created:

Submit details for creating ACS instance

It will take a few minutes to deploy the docker image to the Azure Container Instance. Once deployed, your container is up and running with either a public IP address or a private, internal address. Public addresses can host public-facing services, while private addresses work well for private applications or internal services used to support your public interfaces.

After this, we can browse the application using the URL of the container instance or the public ip address assigned to container instance:

Verify you can access the application in azure

2 thoughts on “Deploy ASP.NET Core App as Azure Containers Instances (ACI)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s