Deploying ASP.NET and SQL SERVER application using Windows Containers on Azure
In this article, we are going to take a look at deploying ASP.NET application and SQL SERVER on a windows container on Azure. We will talk about docker-compose and this topic are relevant when you are running multiple container application.
In most cases, an application has multiple servers involved, multiple containers e.g. a web server container, database server container, a caching server etc. Docker has a special tool called Docker-Compose that is used for defining and running multiple container applications and the way it works is you would create a compose file with yml extension to define the way your application should be built up in terms of services and those services are correspond to containers. The name of the file is docker-compose.yml and in the following we defined our dataset and web server:
As you can see under services we defined sql and iis and iis has a dependency to sql and we also defined the ports. Other details are in Dockerfile.sql and Dockerfile.iis
In Dockerfile.sql , we defined SQL SERVER image and also password and other parameters for running the sql server in container.
In Dockerfile.iis , we defined IIS image and copy the binaries to the root folder of container.
In previous article we saw how to easily spin up a windows server 2016 virtual machine with container support on Azure platform and also saw how to run SQL SERVER in a windows container on Azure.
In order to run ASP.NET application we need to pull down aspnet image from docker hub:
We also need to install docker-compose as it is not installed by default. If we run docker-compose –help we are getting the following error:
We need to run the following command in our container host to install docker-compose:
Invoke-WebRequest https://dl.bintray.com/docker-compose/master/docker-compose-Windows-x86_64.exe -UseBasicParsing -OutFile $env:ProgramFiles\docker\docker-compose.exe
Now if we run docker-compose –help we see that it is showing all contents relevant to docker-compose which shows it has been installed:
The application that we are going to deploy is an ASP.NET MVC application that using Entity Framework to connect to SQL SERVER and it is a simple and basic application where people go to the web site and add/update/delete restaurants. So the application made up of two container instances, we’ve got IIS server for the web application and on the back end we’ve got SQL SERVER Express database where we add/update/delete the data.
We need to publish our application and copy the dockerfile.sql and dockerfile.iis and docker-compose.yml file in a folder let’s call it cuisineApp and we will copy this cuisineApp folder and all its content to our Windows Server 2016 VM on Azure on C drive.
Let’s open the powershell command and cd into this directory and run docker images. We see a list of all pulled images here on this machine:
By convention when you run docker-compose it will look into current directory for file called docker-compose-yml and you really don’t need to tell it which file to use. It will read that file and it will notice that we were referencing other docker files.
Now let’s run below command to build our new image:
So if you run docker images we can see our new images:
Now let’s run docker-compose up to bring up our application:
We are not done yet, at this point we need to open the port 80 on our Windows Server 2016 VM on azure and in order to do that on azure portal we need to set this on network security group for our VM as follow:
Now from my local machine I can access the web site:
Let’s create a new record:
So, that is the concept of a running multi container application using windows container in azure.