<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Read, Write, Speak - Azure</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/maheshkshirsagar/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/feed.xml</link>
    <description>My Azure Journal</description>
    <lastBuildDate>Tue, 27 Mar 2018 05:37:33 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Running ASP.Net Core 2.0 web application on Windows Azure Virtual Machine Scaleset (VMSS)</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/running-asp-net-core-2-0-web-application-on-windows-azure-virtual-machine-scaleset-vmss</link>
      <pubDate>Tue, 27 Mar 2018 10:13:40 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=3415</guid>
      <description><![CDATA[Introduction
Azure Virtual Machine Scale Sets (VMSS) is a group of virtual machines (VMs) that has...]]></description>
      <content:encoded><![CDATA[<h1>Introduction</h1>
Azure Virtual Machine Scale Sets (<a href="https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-overview">VMSS</a>) is a group of virtual machines (VMs) that has identical software running on them. They are great for running workloads which require high scalability and availability. It provides a great option to run a workload which needs identical virtual machines (VMs). Common example of such a workload is a stateless web front-end or web API. It provides a good balance between IaaS and PaaS model by allowing to perform <em>infrastructure</em> operations such as remote desktop connection to individual VM or instance and provisioning other <em>platform</em> components such as virtual network (VNet), Load Balancer, Public IP address, etc.

Just like virtual machines, VMSS can use either Windows or Linux as it's OS.

<a href="https://blogs.msdn.microsoft.com/webdev/2017/08/14/announcing-asp-net-core-2-0/">ASP.Net Core 2.0</a> is an open-source and cross-platform .NET framework for building modern web applications. It provides a unified platform for building web UI and APIs. It can help author applications that can be hosted on IIS, Nginx, Apache or Docker. This flexibility makes it an ideal choice for creating applications that can be hosted on Azure.

This post covers creating and running a ASP.Net Core 2.0 web application running on Windows VMSS. It covers common issues and their resolutions encountered in getting ASP.Net Core 2.0 applications deployed to VMSS.

Sample application code is available at github location - <a href="https://github.com/Mahesh-MSFT/VMSSDemo">https://github.com/Mahesh-MSFT/VMSSDemo</a>
<h1>Deployment options</h1>
VMSS supports 2 main deployment options. They are –
<ol>
 	<li>VM Extension</li>
 	<li>Custom VM Image</li>
</ol>
Many developers are already familiar with VM Extension approach for post-production operations on individual VMs. It offers a great automation experience using tools such as DSC, Chef and Puppet. This same experience can be extended to VMSS as well.

Creating a custom VM image is the most elaborative experience compared to creating a VM extension. This approach mostly used by IT teams to create "golden copies" of specialized software and ticking a checkbox in their BCDR checklist.

Choosing an option makes a difference in how quickly or slowly scaling can be performed. For example, if an VM extension is created, for every new VM that is added in VMSS, needs to wait before it becomes available to take traffic for extension to get provisioned and become active. This makes scaling operation taking longer. On the other hand, although creating a custom image can be arduous task, creating a new VM with custom image and adding it to scaleset is very fast.

This post uses Custom VM Image option to create a new VM using that image and adding it to scaleset.
<h1>Creating the Application</h1>
ASP.Net Core 2.0 has an impressive <a href="https://github.com/aspnet/Home/releases/tag/2.0.0">list of features</a> that makes a web application richer. This post uses <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/razor-pages/?tabs=visual-studio">Razor Page Handler</a> feature to display the current web server name by <a href="https://www.talkingdotnet.com/handle-ajax-requests-in-asp-net-core-razor-pages/">making a AJAX call</a>. This ties back nicely with VMSS where this application will be running on all the VMs making up the VMSS. It will be simply displaying web server name that is serving the page.

To create a ASP.Net Core 2.0 application, click File <span style="font-family: Wingdings">à</span> New in Visual Studio. I am using Visual Studio 2017 in this post, but equivalent steps can also be used in other editors like VSCode.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN1.png" alt="" />

In subsequent dialog box, choose ASP.Net Core 2.0 as the framework and select "Web Application" as template.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN2.png" alt="" />

Resulting application will have a structure as outlined in "Solution Explorer" window below.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN3.png" alt="" />

In the Index.cshtml, I add a AJAX call to <span style="color: black;font-family: Consolas;font-size: 9pt">OnGetServerData </span>function<span style="color: black;font-family: Consolas;font-size: 9pt">. </span>

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN4.png" alt="" /><span style="color: black;font-family: Consolas;font-size: 9pt">
</span>

To add interactivity to page, I call this function every second using Javascript.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN5.png" alt="" />

Server function <span style="color: black;font-family: Consolas;font-size: 9pt">OnGetServerData</span> simply returns name of web server and current timestamp.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN6.png" alt="" />

When running locally, application loads with home page like below.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN7.png" alt="" />
<h1>Setting up CI/CD workflow - Build</h1>
Deploying any application to Azure should be automated using CI/CD workflow. This helps to improve availability as there is no manual intervention involved. For deploying a ASP.Net Core 2.0 application to VMSS, there are following main steps involved.
<ol>
 	<li>Build web application and package it</li>
 	<li>Provision Web Server (IIS)</li>
 	<li>Install ASP.Net Core 2.0</li>
 	<li>Deploy application using WebDeploy</li>
 	<li>Configure application</li>
 	<li>Create a VMSS</li>
 	<li>Update VMSS (If already created)</li>
</ol>
This post will cover how each of the above steps is automated using Visual Studio Team Services (VSTS). All of these steps can be automated equally easy using other CI/CD tools such as Jenkins or TeamCity.
<h2>Build web application and package it</h2>
VSTS offers a pre-packaged build step for ASP.Net Core application as highlighted below.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN8.png" alt="" />

This template provides a standard 4 step process as shown below to build and publish the application.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN9.png" alt="" />
<h2>Provision Web Server (IIS)</h2>
This step starts to prepare destination server. This post shows how to provision IIS server. However, there are similar steps that can be used to provision other web servers such as Nginx or Apache.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN10.png" alt="" />
<h2>Install ASP.Net Core 2.0</h2>
There are 2 components needed to be installed for IIS on Windows servers.
<ol>
 	<li>.NET Core 2.0 SDK</li>
 	<li>.NET Core 2.0 Windows Server Hosting bundle</li>
</ol>
Following powershell script illustrates automating both steps. Note that download path and installable file name will change over the time. Script below uses download path and installable filename as of Feb-18.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN11.png" alt="" />
<h2>Deploy application using WebDeploy</h2>
Earlier, step "Build web application and package it" will create a deployment package in the form of a single zip file. This zip file can be deployed on IIS server using <a href="https://www.iis.net/downloads/microsoft/web-deploy">WebDeploy</a>. Powershell script to download installable and installing it as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN12.png" alt="" />
<h2>Configure application</h2>
When deploying web application using WebDeploy, it gets deployed as a "Virtual Directory" and should be converted to a "Web Application". Script below shows how to do that.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN13.png" alt="" />

A consolidated script to automate steps discussed in earlier section is available <a href="https://github.com/Mahesh-MSFT/VMSSDemo/blob/master/VanilaWebApp/Deploy/deployapp.ps1">here</a>. It's to be checked-in as part of source code for use in build process. Updated build pipeline looks like as shown below. Note that A copy file task copies script from source code/folder to <em>artifactstagingdirectory</em> which is finally published as build output in "<em>Publish Artifact</em>" Step.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN14.png" alt="" /><span style="color: darkred;font-family: Consolas;font-size: 9pt">
</span>
<h1>Setting up CI/CD workflow - Release</h1>
After Build artifacts are generated, it's time to deploy them VSTS offers a "Azure Virtual Machine Scale Set Deployment" task that can pick up build artifacts and deploy them on VMSS.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN15.png" alt="" />
<h2>Deployment Process Task</h2>
This task uses <a href="https://www.packer.io/guides/packer-on-cicd/">Packer</a> template. After adding this task, configure it as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN16.png" alt="" />

Key values to be configured are –
<ol>
 	<li>Packer Template: This should have value "Auto Generated". If you are authoring a custom template, it can be used as well. This post uses "Auto Generated".</li>
 	<li>Azure Subscription: A <a href="https://docs.microsoft.com/en-us/vsts/build-release/concepts/library/service-endpoints">VSTS Service endpoint</a> for Azure.</li>
 	<li>Storage Location: Pick from the Drop-down box.</li>
 	<li>Storage Account: Pick from a list that appears after providing Storage Location. Ensure that it exists before you can configure it here. Ensure that it is "general purpose" kind.</li>
 	<li>Resource Group: Resource Group where VMSS will be created. It should be same as Storage Account Resource Group.</li>
 	<li>Deployment Package: Enter path to deployment package obtained after Build process.</li>
 	<li>Deployment Script: Path to script in Deployment Package.</li>
</ol>
<h2>Build immutable machine image Task</h2>
This task uses the Packer template configured in above step. It adds few more parameters as discussed below.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN17.png" alt="" />

Key parameters to be configured are discussed below.
<ol>
 	<li>Base Image Source: This value can be "Gallery" or "Custom". This post uses "Gallery" which mean OS base image will be fetched from Azure MarketPlace.</li>
 	<li>Base Image: Choose Windows Version.</li>
 	<li>Additional Builder Parameters: Packer uses a default VM size of Standard_D3_v2 to create a VM image. This VM series may not be available in some regions. Packer's default configuration value can be changed by passing additional builder parameter as shown above. Here a "vm_size" parameter with value of "Standard_A2" is passed.</li>
 	<li>Image URL: This variable holds the blob storage location where actual image will be created. By using a variable, it's value can be used in subsequent steps.</li>
</ol>
<h2>Create a VMSS</h2>
Once the immutable image is created in above step, a script can be invoked to either create or update VMSS. Script is available in source code (createorupdatevmss.ps1).

This script in essence calls following powershell cmdlets –
<ol>
 	<li><span style="color: blue"><span style="font-family: Consolas;font-size: 9pt">Update-AzureRmVmss <span style="color: black"><span style="color: navy">-ResourceGroupName <span style="color: black"><span style="color: orangered">$rgname <span style="color: black"><span style="color: navy">-Name <span style="color: black"><span style="color: orangered">$vmssName <span style="color: black"><span style="color: navy">-VirtualMachineScaleSet <span style="color: black"><span style="color: orangered">$vmss</span></span></span></span></span></span></span></span></span></span></span></span></span> (</span>IF VMSS already exists!)</li>
 	<li><span style="color: blue"><span style="font-family: Consolas;font-size: 9pt">New-AzureRmVmss <span style="color: black"><span style="color: navy">-ResourceGroupName <span style="color: black"><span style="color: orangered">$rgname <span style="color: black"><span style="color: navy">-Name <span style="color: black"><span style="color: orangered">$vmssName <span style="color: black"><span style="color: navy">-VirtualMachineScaleSet <span style="color: black"><span style="color: orangered">$vmss <span style="color: black"><span style="color: navy">-Verbose<span style="color: black">; </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>(</span>IF VMSS doesn't already exists!)</li>
</ol>
<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN18.png" alt="" />

Key parameter value above is "Script Arguments". Apart from resource location and resource group name, image URL which holds the image location is passed as an argument.

When this script finishes running, a VMSS is created if it didn't exist before or is updated with new image if it existed already.
<h1>Common troubleshooting</h1>
Below are some common troubleshooting techniques to overcome issues that may surface with approach described above.
<h2>Enable Packer Logging</h2>
Packer does most of the processing to create images. Without a proper debugging assistance, it's a problem to identify what is happening and potentially going wrong.

Image below shows how it's possible to enable Packer logging.

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN19.png" alt="" />

Some common examples of issues that can be captured by enabling Packer logging are –
<ol>
 	<li>VM Size not supported in a region.</li>
 	<li>Site doesn't exist</li>
 	<li>The supplied password must be between 8-123 characters long and must satisfy at least 3 of password complexity requirements</li>
</ol>
To identify exact error description, download Build or Release log file and search for "error" word.
<h2>Use General Purpose Storage account to store VMSS image</h2>
Ensure that the storage account used to hold the VMSS image is of type "General Purpose".

<img src="https://msdnshared.blob.core.windows.net/media/2018/03/032718_0437_RunningASPN20.png" alt="" />
<h2>Use Custom Image for VMSS</h2>
Ensure that when you run above script, VMSS (with MarketPlace image) is not created beforehand using portal. Approach described above works with VMSS created using custom image. If you start with a pre-created VMSS using MarketPlace image, you'll get following error.

scaleset The property 'uri' cannot be found on this object. Verify that the property exists and can be set
<h2>Use a private VSTS agent over hosted VSTS agent</h2>
Approach explained above uses VSTS hosted agent. This is default VSTS agent. Note that this agent has a default timeout setting of 30 mins. Creating a VMSS image and applying it to a new or existing image can easily take more than 30 mins. Depending upon, at what point build or release process times out, you may encounter following error.

<img src="image003.jpg@01D3B08E.A5BD2F40" alt="" /><img src="https://msdnshared.blob.core.windows.net/media/2018/03/VSTSErr.png" alt="" width="986" height="531" class="alignnone size-full wp-image-3755" />

A workaround is to manually run the last script by passing parameter values.

<span style="color: darkgreen;font-family: Consolas;font-size: 9pt">vmsscreateorupdate.ps1 CreateOrUpdateScaleSet -loc '&lt;your azure region&gt;' -rgname '&lt;your rg&gt;' -imageurl "&lt;your Image VHD Location"</span>]]></content:encoded>
    </item>
    <item>
      <title>Choosing the right Kubernetes object for deploying workloads in Azure</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/choosing-the-right-kubernetes-object-for-deploying-workloads-in-azure</link>
      <pubDate>Wed, 25 Oct 2017 13:17:31 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=3276</guid>
      <description><![CDATA[I have published a blog series on AzureCAT guidance blog for choosing the right Kubernetes object...]]></description>
      <content:encoded><![CDATA[I have published a blog series on <a target="_blank" href="https://blogs.msdn.microsoft.com/azurecat/" rel="noopener noreferrer">AzureCAT guidance blog</a> for choosing the right Kubernetes object for deploying workloads in Azure.

It consists of following posts:
<ol>
 	<li><a target="_blank" href="https://blogs.msdn.microsoft.com/azurecat/2017/10/24/choosing-the-right-kubernetes-object-for-deploying-workloads-in-azure-part-1/" rel="noopener noreferrer">Part 1</a>: This post covers setting up Kubernetes locally. It talks about<span> </span><em>minikube</em>,<span> </span><em>kubectl,<span> </span></em>and so on.</li>
 	<li><a target="_blank" href="https://blogs.msdn.microsoft.com/azurecat/2017/10/24/choosing-the-right-kubernetes-object-for-deploying-workloads-in-azure-part-2/" rel="noopener noreferrer">Part 2</a>: This post covers setting up a Kubernetes cluster in Azure using Azure Container Service (ACS). It covers deployment options in Azure, deployment process, and connecting to a cluster by using a proxy.</li>
 	<li><a target="_blank" href="https://blogs.msdn.microsoft.com/azurecat/2017/10/24/choosing-the-right-kubernetes-object-for-deploying-workloads-in-azure-part-3/" rel="noopener noreferrer">Part 3</a>: This post is a high-level conceptual overview of Kubernetes. It covers various<span> </span><em>menu</em><span> </span>options in the Kubernetes dashboard.</li>
 	<li><a target="_blank" href="https://blogs.msdn.microsoft.com/azurecat/2017/10/24/choosing-the-right-kubernetes-object-for-deploying-workloads-in-azure-part-4/" rel="noopener noreferrer">Part 4</a>: This post covers deploying the SQL Server back-end, including choosing the right deployment object for running a database, the actual deployment process, and the interaction with SQL Server from SQL Server Management Studio.</li>
 	<li><a target="_blank" href="https://blogs.msdn.microsoft.com/azurecat/2017/10/24/choosing-the-right-kubernetes-object-for-deploying-workloads-in-azure-part-5/" rel="noopener noreferrer">Part 5</a>: This post covers deploying the ASP.Net Core web front-end, choosing the right deployment object, the actual deployment process, monitoring the cluster, and verification of the application working with the back-end.</li>
</ol>
Get started with <a target="_blank" href="https://blogs.msdn.microsoft.com/azurecat/2017/10/24/choosing-the-right-kubernetes-object-for-deploying-workloads-in-azure/" rel="noopener noreferrer">this</a> introductory post of the series.]]></content:encoded>
    </item>
    <item>
      <title>Running Spring Boot Java application as a Microservice in Service Fabric</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/running-spring-boot-java-application-as-a-microservice-in-service-fabric</link>
      <pubDate>Thu, 22 Jun 2017 17:56:00 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=2555</guid>
      <description><![CDATA[Spring Boot Framework is one of the popular frameworks to author RESTful APIs using Java. It is very...]]></description>
      <content:encoded><![CDATA[Spring Boot Framework is one of the popular frameworks to author RESTful APIs using Java. It is very commonly used alongwith Angular and Kafka to create distributed applications.  In this series of posts, I'll cover how a Spring Boot application can be deployed and run as a microservice using Azure Service Fabric. Below is table of content for each post and what it covers.
<ol>
 	<li><a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-1/">Part 1</a>: Creating a Spring Boot application and getting it to run locally.</li>
 	<li><a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-2/">Part 2</a>: Getting this application deployed and running in local Service Fabric cluster.</li>
 	<li><a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-3/">Part 3</a>: Deploying this application to Azure Service Fabric cluster using CI/CD pipeline defined in VSTS.</li>
 	<li><a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-4/">Part 4</a>: Containerizing this application and getting it running as a container in Azure Service Fabric.</li>
</ol>
Source code for application is available at following GitHub locations.
<ol>
 	<li><a target="_blank" href="https://github.com/Mahesh-MSFT/sbmjar">Spring Boot Application (Maven)</a></li>
 	<li><a target="_blank" href="https://github.com/Mahesh-MSFT/sbmsf">Spring Boot Application (Service Fabric)</a></li>
</ol>
&nbsp;

&nbsp;

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Running Spring Boot Java application as a Microservice in Service Fabric - Part 4</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-4</link>
      <pubDate>Thu, 22 Jun 2017 17:44:50 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=2375</guid>
      <description><![CDATA[This series so far covered how Service Fabric can run Spring Boot application using JAR file. It...]]></description>
      <content:encoded><![CDATA[<a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric/">This series</a> so far covered how Service Fabric can run Spring Boot application using JAR file. It uses java.exe which is bundled along with application to run this JAR file. This post will cover a more elegant approach - using containers instead of a full runtime.

Service Fabric already supports running Windows containers on <a target="_blank" href="https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-deploy-container">Windows cluster</a> and docker/linux containers on <a target="_blank" href="https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-deploy-container-linux">Linux cluster</a>. With Hyper-V container support on <a target="_blank" href="https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-containers-overview#container-types">roadmap</a>, Service Fabric will be able to provide better isolation for multi-tenant applications where customers prefer to share nothing.

Coming back to Spring Boot application,  it can be either containerized to a linux container or windows container with just a single line change and I'll cover how soon.

Lets start with windows container.

To containerize Spring Boot application, add dockerfile at the same location as pom.xml file. Let's look at content inside.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMDockerfile.png" alt="" width="811" height="194" class="alignnone size-full wp-image-2376" />
<ul>
 	<li>1st line is commented out (denoted by #). It is actually a switch between linux and windows container. If comment is removed, it will generate a linux container image.</li>
 	<li>2nd line is base image on top of which new image of application will be created. In this example, base image is of openjdk for windows server core available on <a target="_blank" href="https://hub.docker.com/_/openjdk/">Docker Hub</a>.</li>
 	<li>3rd line exposes port 8080 on container.</li>
 	<li>4th line adds jar file from target folder in source directory to container.</li>
 	<li>5th line configures java to run added jar file using -jar switch.</li>
</ul>
In <a target="_blank" href="https://store.docker.com/editions/community/docker-ce-desktop-windows">Docker for Windows</a>, switch to Windows container mode as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMWinCont.png" alt="" width="254" height="325" class="alignnone size-full wp-image-2395" />

Navigate to folder containing dockerfile and issue following command.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMdockerbuild-1024x38.png" alt="" width="1024" height="38" class="alignnone size-large wp-image-2396" />

This command is going to use dockerfile described above (denoted by . in the end) and create a container image called maksh/sbmappimagewin.

Once this command completes successfully (This may take some time due to large size base image!). Run following command to verify new image is successfully created.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMDockerImages-1024x116.png" alt="" width="1024" height="116" class="alignnone size-large wp-image-2415" />

Now run a container from this image using following command.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMDockerRun-1024x119.png" alt="" width="1024" height="119" class="alignnone size-large wp-image-2416" />

Switch -d is for running command in detached mode. -p is for port mapping between host and container port. A new container with Id 9d* has been successfully created. Lets extract its IP address by executing following command.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMdockerexec-1024x408.png" alt="" width="1024" height="408" class="alignnone size-large wp-image-2425" />

Command above executes <em>ipconfig</em> on container identified by 9d (2 initials that uniquely identifies this container). Copy the IP address and navigate to <em>IP:PortNo</em> combination.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMContApp.png" alt="" width="457" height="175" class="alignnone size-full wp-image-2435" />

Spring Boot application is now running as a windows container locally. Next step is to push it to Docker Hub so that it can be used for deployment anywhere we want. Use docker login and push commands as illustrated below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMDockerPush-1024x187.png" alt="" width="1024" height="187" class="alignnone size-large wp-image-2445" />

Local image (maksh/sbmappimagewin) should be available in Docker Hub after push operation completes successfully.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMDockerHub-1024x395.png" alt="" width="1024" height="395" class="alignnone size-large wp-image-2446" />

Now, this container image can be used to deploy application on service fabric. Open the Service Fabric VS Solution we created in part 2.

Delete the "Code" folder from solution.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMDel.png" alt="" width="601" height="446" class="alignnone size-full wp-image-2485" />

Comment out the ExeHost section and add new ContainerHost section in ServiceManifest.xml file as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMContHost.png" alt="" width="975" height="414" class="alignnone size-full wp-image-2455" />

Add additional section as shown below in ApplicationManifest.xml file. Repository credentials are same as the ones used to connect with Docker Hub and push container image. Ensure that EndpointRef refers to Endpoint Name as in ServiceManifest.xml file.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMAppManPol1-1024x240.png" alt="" width="1024" height="240" class="alignnone size-large wp-image-2475" />

Next, select the project in solution explorer, right click and select "Publish".

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMPackage.png" alt="" width="600" height="449" class="alignnone size-full wp-image-2505" />

In dialog box that appears, select Cloud.xml as Target profile and Connection endpoint pointing to Azure Service Fabric cluster.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMContPub1.png" alt="" width="630" height="428" class="alignnone size-full wp-image-2515" />

Verify that application is successfully deployed by navigating to Azure Service Fabric Explorer.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMJarCont1-1024x562.png" alt="" width="1024" height="562" class="alignnone size-large wp-image-2535" />

Finally, verify application as well :-)

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMContJar.png" alt="" width="570" height="254" class="alignnone size-full wp-image-2545" />

There it is again - a Spring Boot application running as a container in Service Fabric.]]></content:encoded>
    </item>
    <item>
      <title>Running Spring Boot Java application as a Microservice in Service Fabric - Part 3</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-3</link>
      <pubDate>Thu, 22 Jun 2017 17:43:51 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=2135</guid>
      <description><![CDATA[Let'd do a quick summary of previous 2 posts.

Part 1: Covered creating Spring Boot application...]]></description>
      <content:encoded><![CDATA[Let'd do a quick summary of previous 2 posts.

<a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-1/">Part 1</a>: Covered creating Spring Boot application using Eclipse

<a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-2/">Part 2</a>: Covered deploying this application to service fabric on a local cluster.

In this post,  we'll take a look at how we can use Visual Studio Team Services (VSTS) for implementing CI/CD pipeline to deploy to Azure. Project which I was working on has been pushed to GitHub and I'll use it as a source control repository to start CI/CD process.

Ensure that you copy JRE folder and following Service Fabric specific files to Sprint Boot application and keep them at same location as pom.xml.
<ol>
 	<li>JRE: Folder that we earlier copied inside Code folder in Service Fabric solution.</li>
 	<li>ApplicationManifest.xml</li>
 	<li>ApplicationParameters.xml</li>
 	<li>PublishProfile.xml</li>
 	<li>ServiceManifest.xml</li>
</ol>
<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMSFFiles1.png" alt="" width="620" height="286" class="alignnone size-full wp-image-2206" />

Lets start with building CI/CD pipeline. Navigate to "Build" menu in VSTS home page and click "New" button.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMNewBuild-1024x146.png" alt="" width="1024" height="146" class="alignnone size-large wp-image-2136" />

Select "Empty" as a template.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMTemplate-1024x521.png" alt="" width="1024" height="521" class="alignnone size-large wp-image-2145" />

Select the "Github" as source control repository. You can also choose from other options shown. Select repository and branch name.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMRepo-1024x677.png" alt="" width="1024" height="677" class="alignnone size-large wp-image-2155" />

Next add a Maven Build as a task.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMMavenBuild-1024x250.png" alt="" width="1024" height="250" class="alignnone size-large wp-image-2175" />

Select the Maven version, path to pom.xml file and goal(package).

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMMavenConf-1024x383.png" alt="" width="1024" height="383" class="alignnone size-large wp-image-2185" />

Next add a "Copy Files" task to copy JAR file generated by previous Maven build step and configure as shown below. We will create a service fabric VS solution structure using CI/CD pipeline.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMCopyFIles-1024x318.png" alt="" width="1024" height="318" class="alignnone size-large wp-image-2195" />

Note <em>target</em> folder is in source location denoted by variable $(build.sourcesdirectory). Maven build step generates JAR file in this source directory location. Specify **/sbmartifact.jar in "Contents" box, which is JAR file name as mentioned in pom.xml file.  Finally copy this jar file to a staging directory denoted by build variable $(build.artifactstagingdirectory). This is where we start to construct service fabric VS solution structure. Folder stucture specified here is <em>Root/Package/JarApiSFAppPkg/Code</em>.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMCopyJAR-1024x373.png" alt="" width="1024" height="373" class="alignnone size-large wp-image-2196" />

Next add task to copy JRE folder

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMCopyJRE-1024x371.png" alt="" width="1024" height="371" class="alignnone size-large wp-image-2216" />

Add Copy ApplicationManifest.xml file task. Note target folder location. It's at root of the <em>Package.</em>

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMCopyAppMani-1024x369.png" alt="" width="1024" height="369" class="alignnone size-large wp-image-2225" />

<span>Add Copy ServiceManifest.xml file task. Note target folder location. It's 1 level below root <em>Package</em></span><em>.</em>

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMCopySerMan-1024x362.png" alt="" width="1024" height="362" class="alignnone size-large wp-image-2235" />

Now copy ApplicationParameters.xml and PublishProfile.xml files.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMCopyProf-1024x371.png" alt="" width="1024" height="371" class="alignnone size-large wp-image-2245" />

Finally, add a "Publish Build Artifact" task. Publish <em>Root</em> folder that was constructed by earlier tasks.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMPubArt-1024x366.png" alt="" width="1024" height="366" class="alignnone size-large wp-image-2255" />

After this build finishes its run, take a look at "Artifact Explorer". It should have all files and directories arranged as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMBuildArt.png" alt="" width="732" height="320" class="alignnone size-full wp-image-2265" />

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMArtExpl.png" alt="" width="548" height="735" class="alignnone size-full wp-image-2275" />

We now have got all the build artifacts ready for deployment to Azure. Let's see how we can deploy this application to Azure. There are 2 pre-requisites before we can get started with deployment.
<ol>
 	<li>A Service Fabric cluster already deployed in Azure. See <a target="_blank" href="https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-cluster-creation-via-portal">these instructions</a> for setting this up.</li>
 	<li>Azure Service Fabric Endpoint in VSTS. See <a target="_blank" href="https://www.visualstudio.com/en-us/docs/build/concepts/library/service-endpoints#sep-servfabric">these instructions</a> for setting this up.</li>
</ol>
One above pre-requisites are fulfilled, lets go back to our build definition. Click Build &amp; Release --&gt; Releases--&gt; +create release definition.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMNewRel.png" alt="" width="807" height="322" class="alignnone size-full wp-image-2285" />

Select "Azure Service Fabric Deployment" as a template.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMSFDep.png" alt="" width="663" height="732" class="alignnone size-full wp-image-2295" />

Select the "Source (Build Definition)" we just created from the drop-down. Ensure "Continuous deployment" checkbox is ticked.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMSFDep2.png" alt="" width="658" height="728" class="alignnone size-full wp-image-2305" />

Click "Create" button and a screen as shown below should be presented.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMSFDep3-1024x506.png" alt="" width="1024" height="506" class="alignnone size-large wp-image-2306" />

&nbsp;

Populate values as shown below.
<ol>
 	<li>Application Package: This value should be Root/Package folder.</li>
 	<li>Cluster Connection: This value should be selected from drop-down. It is populated by azure service fabric endpoint set as pre-requisite.</li>
 	<li>Publish Profile: Should be used to connect with Azure based SF cluster. An example is shown below.</li>
 	<li>Applicaiton Parameters: It is referred from Publish Profile. Typically contains <em>instance_count</em> setting for service.</li>
</ol>
<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMDep-1024x281.png" alt="" width="1024" height="281" class="alignnone size-large wp-image-2315" />

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMPubProf-1024x396.png" alt="" width="1024" height="396" class="alignnone size-large wp-image-2325" />

Now, deploy this release and verify all deploy steps are completed successfully.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMDepSuc-1024x595.png" alt="" width="1024" height="595" class="alignnone size-large wp-image-2345" />

Navigate to Azure Service Fabric Explorer and verify application has got deployed successfully and cluster is healthy.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMAz-1024x543.png" alt="" width="1024" height="543" class="alignnone size-large wp-image-2335" />

Given that this application runs on port 8080, a load-balancing rule needs to be added to Sevice Fabric cluster in Azure as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMLB-1024x548.png" alt="" width="1024" height="548" class="alignnone size-large wp-image-2386" />

Once the load-balancing rule is added, verify that application is working as expected navigating to service fabric URL.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMSFApp.png" alt="" width="625" height="276" class="alignnone size-full wp-image-2355" />

There it is - a Spring Boot Fat Jar application running as a microservice in Service Fabric in Azure using CI/CD pipeline in VSTS.

But there's more! in <a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-4/">next part</a>, I'll show how to containerize this application and run it in Service Fabric as a container.]]></content:encoded>
    </item>
    <item>
      <title>Running Spring Boot Java application as a Microservice in Service Fabric - Part 2</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-2</link>
      <pubDate>Thu, 22 Jun 2017 17:43:09 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=2026</guid>
      <description><![CDATA[Previous post covered creating a fat JAR application and running it locally.

In this post we'll...]]></description>
      <content:encoded><![CDATA[<a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-1/">Previous post</a> covered creating a fat JAR application and running it locally.

In this post we'll look at how we can run this JAR application as a microservice in Service Fabric. <a href="https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-get-started-eclipse#build-and-deploy-the-service-fabric-application-using-eclipse">Service Fabric Plugin for Eclipse</a> makes it very easy to deploy from Eclipse on Linux/Mac platforms as described <a target="_blank" href="https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-get-started-eclipse#build-and-deploy-the-service-fabric-application-using-eclipse">here</a>. If you are using Windows as a development/deployment platform you can use <a target="_blank" href="https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-get-started">Visual Studio 2017 with Service Fabric SDK</a>. In this post, I'll use Visual Studio 2017.

Start Visual Studio and click File--&gt;New. Select "Cloud" under Templates and "Service Fabric Application" on the right-hand side pane.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMVSNew.png" alt="" width="941" height="653" class="alignnone size-full wp-image-2035" />

In next dialogue, select "Guest Executable" as a service template. Folder location containing JAR file as "Code Package Folder" and name of service in "Service Name".

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMVSServiceDialog.png" alt="" width="786" height="578" class="alignnone size-full wp-image-2045" />

Visual Studio creates a solution structure  as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMVSSolution.png" alt="" width="567" height="340" class="alignnone size-full wp-image-2055" />

Now, lets add the JAR file to "Code" folder shown above. To do so, right click it, select "Add an existing Item", navigate to folder containing JAR file and select it.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMAddJAR.png" alt="" width="1021" height="470" class="alignnone size-full wp-image-2056" />

Along with JAR, we also need to upload runtime to run this JAR file. Typically, this is JRE. It generally resides in the JDK installation folder (C:\Program Files\Java\jdk1.8.0_131).

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMJRE-1024x403.png" alt="" width="1024" height="403" class="alignnone size-large wp-image-2065" />

Simply copy this folder and paste it on "Code" folder in VS.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMJRECopy.png" alt="" width="476" height="474" class="alignnone size-full wp-image-2066" />

After copy, solution structure in VS should look like below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMVSSoln.png" alt="" width="306" height="391" class="alignnone size-full wp-image-2076" />

Now, navigate to "ServiceManifest.xml" file in Service Fabric solution. Change following parameters as shown below.
<ol>
 	<li>Program: This should point to java.exe file in JRE folder that was copied.</li>
 	<li>Arguments: This should contain the <em>-jar</em> and <em>path of the JAR filename</em> relative to java.exe. They are arguments passed to java.exe when it starts.</li>
 	<li>WorkingFolder: This should be CodeBase.</li>
 	<li>Endpoint: Name a endpoint and provide protocol as HTTP and port no (8080) along with type(input).</li>
</ol>
<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMServMani.png" alt="" width="906" height="706" class="alignnone size-full wp-image-2085" />

Next open the "ApplicationManifest.xml" file and verify its settings as shown below. Pay attention to name, type of the Service. They should match in ServiceManifest and ApllicaitonManifest files.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMAppMani-1024x567.png" alt="" width="1024" height="567" class="alignnone size-large wp-image-2086" />

Click "Start" button in Visual Studio and wait for a successful deployment to local SF cluster.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBmRun-1024x576.png" alt="" width="1024" height="576" class="alignnone size-large wp-image-2095" />

Navigate the local service fabric cluster endpoint at https://localhost:19080/Explorer/index.html#/ and validate application is deployed and running successfully.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMSFCluster-1024x594.png" alt="" width="1024" height="594" class="alignnone size-large wp-image-2105" />

Application is now running on service fabric cluster. Verify by navigating to localhost:8080 and it should return the IP address.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMLocalhost.png" alt="" width="583" height="292" class="alignnone size-full wp-image-2115" />

At this point, we can potentially deploy this application to Azure. However, let's see how we can implement a CI/CD pipeline to deploy to Azure in <a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-3/">next post</a>.]]></content:encoded>
    </item>
    <item>
      <title>Running Spring Boot Java application as a Microservice in Service Fabric - Part 1</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-1</link>
      <pubDate>Thu, 22 Jun 2017 17:42:34 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=1795</guid>
      <description><![CDATA[This post covers authoring a new Spring Boot application using Maven.

Start Eclipse and start...]]></description>
      <content:encoded><![CDATA[This post covers authoring a new Spring Boot application using Maven.

Start Eclipse and start with File--&gt;New--&gt;Maven Project.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMFileNew.png" alt="" width="672" height="488" class="alignnone size-full wp-image-1805" />

Select convenient location to save.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMFolder.png" alt="" width="592" height="541" class="alignnone size-full wp-image-1815" />

Select webapp as archetype.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMArcheType.png" alt="" width="592" height="541" class="alignnone size-full wp-image-1825" />

Provide a name for your application/JAR file.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMArtifact.png" alt="" width="592" height="541" class="alignnone size-full wp-image-1826" />

Navigate to pom.xml file thus generated. Change the packaging from WAR to JAR. Add additional sections for <em>properties</em> and <em>dependencies</em>. I am using Java 1.8 as depicted below.

More dependencies will be added in <em>dependencies</em> section.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMJar-1024x409.png" alt="" width="1024" height="409" class="alignnone size-large wp-image-1827" />

1st dependency to be added is Spring Boot Framework. Navigate to <a target="_blank" href="https://projects.spring.io/spring-boot/">Spring Boot Website</a>, click "PROJECTS".

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMSpring-1024x100.png" alt="" width="1024" height="100" class="alignnone size-large wp-image-1836" />

Select and copy parent and dependency sections for Maven.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMMavenConfig.png" alt="" width="707" height="539" class="alignnone size-full wp-image-1845" />

Paste copied content inside pom.xml file as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMSpringConfig.png" alt="" width="894" height="531" class="alignnone size-full wp-image-1855" />

Next add <a target="_blank" href="https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper">Tomcat Embed Jasper</a> dependency.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMJasperHomePage-1024x440.png" alt="" width="1024" height="440" class="alignnone size-large wp-image-1865" />

Ensure that a "Release" version is chosen before you copy the Maven config settings.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMJasperRelease-1024x522.png" alt="" width="1024" height="522" class="alignnone size-large wp-image-1885" />

Select Maven specific config settings.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMJasperPOM.png" alt="" width="876" height="666" class="alignnone size-full wp-image-1895" />

Add <a target="_blank" href="https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat">Spring Boot Tomcat Starter</a> dependency. Ensure that "Release" version is selected.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMTomcatHome-1024x525.png" alt="" width="1024" height="525" class="alignnone size-large wp-image-1915" />

Copy Maven specific config setting and paste it to pm.xml.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMTomcatPOM-1024x524.png" alt="" width="1024" height="524" class="alignnone size-large wp-image-1916" />

Next, add Maven plugin itself by navigating to <a target="_blank" href="https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html">Spring Boot Maven Plugin website</a>. Copy plugin config setting as highlighted below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMMavenPlugin-1024x594.png" alt="" width="1024" height="594" class="alignnone size-large wp-image-1926" />

After copying 4 dependencies - Spring Boot Frameork, Tomcat Embed Jasper, Spring Boot Tomat Starter and Maven plugin - pom.xml file should look like as below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMPOM.png" alt="" width="876" height="691" class="alignnone size-full wp-image-1935" />

Now start writing some code :-) Add a Application class which will bootstrap application. Ensure that checkbox for creating <em>public static void main </em>is ticked.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMApplicaiton.png" alt="" width="528" height="631" class="alignnone size-full wp-image-1945" />

Skeleton of class should look something like below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMApplicaitonSkel.png" alt="" width="406" height="185" class="alignnone size-full wp-image-1955" />

Now add Spring specific attributes and routes so that class looks like below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMApplicaitonComplete.png" alt="" width="673" height="493" class="alignnone size-full wp-image-1965" />

In this example, I am simply returning HOST name as a JSON from our Spring Boot API.

Now, let's clean the files and directories during compilation of application. Navigate to path where pom.xml file resides and issue mvn clean command as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMMVNClean-1024x496.png" alt="" width="1024" height="496" class="alignnone size-large wp-image-1975" />

Now, lets build and package our fat JAR file. To do that, issue mvn install command as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMMVNInstall-1024x162.png" alt="" width="1024" height="162" class="alignnone size-large wp-image-1985" />

After a successful completion, following message should appear.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMMVNInstallSuccess-1024x402.png" alt="" width="1024" height="402" class="alignnone size-large wp-image-1995" />

A fat JAR file should be created in target folder as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMFatJar.png" alt="" width="923" height="194" class="alignnone size-full wp-image-2005" />

&nbsp;

Lets run application by running following command.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMJava-1024x414.png" alt="" width="1024" height="414" class="alignnone size-large wp-image-2015" />

When it starts successfully, note down port number on which it has started. In my case, it is port 8080 as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMPort-1024x101.png" alt="" width="1024" height="101" class="alignnone size-large wp-image-2016" />

Navigate to localhost:&lt;portno&gt; and verify if application is running.

<img src="https://msdnshared.blob.core.windows.net/media/2017/06/SBMApp.png" alt="" width="415" height="133" class="alignnone size-full wp-image-2025" />

We now have got a fat JAR spring boot application running locally.

In <a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/06/22/running-spring-boot-java-application-as-a-microservice-in-service-fabric-part-2/">next post</a>, let's see how we can use Service Fabric to run this application.]]></content:encoded>
    </item>
    <item>
      <title>Implementing Rolling Updates in Azure Container Service (ACS) with Docker Swarm using VSTS</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/implementing-rolling-updates-in-azure-container-service-acs-with-docker-swarm-using-vsts</link>
      <pubDate>Thu, 02 Mar 2017 16:23:26 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=1635</guid>
      <description><![CDATA[Docker 1.13 was released recently. 1 of the important feature that came out of this release was...]]></description>
      <content:encoded><![CDATA[<a target="_blank" href="https://blog.docker.com/2017/01/whats-new-in-docker-1-13/">Docker 1.13</a> was released recently. 1 of the important feature that came out of this release was simplified deployment using <em>docker-compose</em> file. Also debuted is new <a target="_blank" href="https://docs.docker.com/compose/compose-file/#version-3">compose file v3</a>. As of  now(Feb-17), it is most current and recommended compose file format.  To understand what new features this enables, refer to <a target="_blank" href="https://docs.docker.com/compose/compose-file/compose-versioning/#/version-3">this</a> link. A new configuration option, <em><a target="_blank" href="https://docs.docker.com/compose/compose-file/#/deploy">deploy</a></em>, brings a lot of goodness to overall deployment(including rolling updates) process in swarm mode. In this post, I'll discuss this new configuration option and use it to implement rolling updates.

<em><strong>Deploy</strong> </em>configuration option is available ONLY in docker compose v3 file format. It has following sub-configuration options -

<em>mode</em>: This option is used to determine how containers gets deployed on swarm cluster. There are 2 possible values: <em>global</em> and <em>replicated</em>. <em>global</em> value makes a instance of container to be deployed on every swarm node. <em>replicated</em> value makes swarm to ensure at least X instances (where X is value provided by <em>replicas</em> value) of containers are running at all times.

<em>replicas</em>: It determines the number of containers running at any point in time. This setting works together with <em>mode</em> value of <em>replicated</em>.

<em>placement</em>: It defines the placement constraints. They are useful in specifying conditions for containers such as OS requirements or node type.

<em>update_config</em>: This setting determines how upgrade to a running service are applied. This is the core setting that drives rolling updates in Swarm mode. This option has following sub-options -
<ul>
 	<li><em>parallelism</em>: This value determines how many containers are updated during upgrade.</li>
 	<li><em>delay</em>: Amount of time to wait between last and next container upgrade.</li>
 	<li><em>failure_action</em>: Action to take in case container upgrade fails. It can take any one of the 2 values (continue or pause). Default is pause.</li>
 	<li><em>monitor</em>: Amount of time for which a container is monitored for failure.</li>
 	<li><em>max_failure_ratio</em>: Percentage value between o.o and 1.0 to determine tolerance of upgrade faulure before entire deploy process is declated a failure.</li>
</ul>
<em>resources</em>: This value is used to set the constraints on resources a container is allowed to use. It is combination of reservation as well as limits.

<em>restart_policy</em>: This value determines a service's restart behavior.

<em>labels</em>: They are used to label the service.

Now that we have looked at <strong><em>deploy</em> </strong>configuration option, let's switch to Azure Container Service (ACS) and Docker Swarm.

Up until now, <em>docker-compose</em> file is used with <em>docker-compose</em> command (docker-compose -up) as below.

<img src="https://msdnshared.blob.core.windows.net/media/2016/11/dockercompoeup.png" alt="dockercompoeup" width="619" height="50" class="alignnone size-full wp-image-1045" />

New guideline however is to use it with <em><strong>deploy</strong> </em>command. This command is available as part of docker daemon (server) running in <em>experimental</em> mode. ACS, by default, doesn't deploy docker daemon in experimental mode. So first step is to spin up ACS with server in experimental mode. With Azure Container Service now <a target="_blank" href="https://azure.microsoft.com/en-in/blog/azure-container-service-the-cloud-s-most-open-option-for-containers/">open sourced</a>, it is very easy to take a look at code, clone/fork it and use it to run the <em>customized</em> ACS engine in Azure.

Instructions to run a customized ACS engine locally are specified <a target="_blank" href="https://github.com/Azure/acs-engine/blob/master/docs/acsengine.md">here. </a> After the source code is cloned locally, simplest option is to use "Docker for Windows" for ACS customization. There are few pre-requisites that needs to be in place first. These pre-requisites are discussed below. It is required to have local drive "<em>Shared</em>". This setting needs to be set as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/rudockershare.png" alt="rudockershare" width="830" height="548" class="alignnone size-large wp-image-1685" />

After clicking "Apply" button, copy the powershell command listed in the prompt.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/rudockershare2-1024x205.png" alt="rudockershare2" width="1024" height="205" class="alignnone size-large wp-image-1675" />

Once the drive is shared, execute the devenv.ps1 script. This script is available inside <em>/scripts</em> folder that comes along with ACS source code.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/rurunshell-1024x425.png" alt="rurunshell" width="1024" height="425" class="alignnone size-large wp-image-1645" />

Once the script execution is finished, a container is spun up and a console logged into it is available to execute further commands. Any IDE/Editor can now be used to change code as required.

To enable ACS engine run with docker server in experimental mode, change <em>\acs-engine\parts\configure-swarmmode-cluster.sh</em> file as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/ruupdatedockerdaemon-1024x159.png" alt="ruupdatedockerdaemon" width="1024" height="159" class="alignnone size-large wp-image-1636" />

After code change, build the codebase again by executing following command.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/rumakebuild-1024x23.png" alt="rumakebuild" width="1024" height="23" class="alignnone size-large wp-image-1655" />

When build finishes, a customized ACS engine is locally available.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/rumakebuildsuccess.png" alt="rumakebuildsuccess" width="1023" height="480" class="alignnone size-full wp-image-1695" />

Run <em>acs-engine</em> command on the prompt available to understand usage of the command.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/ruacsengine-1024x406.png" alt="ruacsengine" width="1024" height="406" class="alignnone size-large wp-image-1705" />

To get this <em>local</em> ACS engine deployed to Azure, use instructions available <a target="_blank" href="https://github.com/ams0/acs-engine/blob/master/docs/swarmmode.md">here</a>. The process in nutshell has following key steps.
<ol>
 	<li><a target="_blank" href="https://github.com/Azure/acs-engine/blob/master/docs/acsengine.md#downloading-and-building-acs-engine">Install acs-engine</a> l<span>ocally. This step is already discussed above.</span></li>
 	<li><a target="_blank" href="https://github.com/Azure/acs-engine/blob/master/docs/ssh.md#ssh-key-generation">Generate SSH key</a></li>
 	<li>Edit the <a target="_blank" href="https://github.com/Azure/acs-engine/blob/master/examples/swarmmode.json">Swarm Mode example</a> and fill in the blank strings</li>
 	<li><a target="_blank" href="https://github.com/Azure/acs-engine/blob/master/docs/acsengine.md#generating-a-template">Generate the template</a></li>
 	<li><a target="_blank" href="https://github.com/Azure/acs-engine/blob/master/README.md#deployment-usage">Deploy the output azuredeploy.json and azuredeploy.parameters.json</a></li>
</ol>
A swarm mode file (referred in step 2 above) is available at <em>/acs-engine/examples</em> folder in the source code. It typically looks as below and can be changed to suit requirements. Ensure that <em>dnsPrefix</em> value is different for maser and agent. It is also possible to change other values such as agent and master counts, VM sizes for both, SSH public key data, etc.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/ruswarmmode1-1024x595.png" alt="ruswarmmode" width="1024" height="595" class="alignnone size-large wp-image-1715" />

This file is to be used to generate azure deploy template. Use following command to generate the template.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/ruswarmmodesuccess-1024x124.png" alt="ruswarmmodesuccess" width="1024" height="124" class="alignnone size-large wp-image-1725" />

Note that acs-engine simply takes the path of <em>swarmmode.json</em> file. After command successfully executes, it generates a folder called as <em>_output</em>. One more sub-folder (with name as hash of the SSH key is also created). This new sub-folder has following 3 files.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/ruoutput.png" alt="ruoutput" width="999" height="147" class="alignnone size-full wp-image-1735" />

<em>azuredeploy.parameters</em> file is to be modified to include an additional <em>nameSuffix</em> node as shown below.

<em>"nameSuffix": {</em>
<em> "value": "&lt;sub-folder name inside _output folder&gt;"</em>
<em> },</em>

After changes, file looks something like below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/ruparameters.png" alt="ruparameters" width="780" height="722" class="alignnone size-full wp-image-1745" />

To deploy to Azure, use 1 of the options as described <a target="_blank" href="https://github.com/Azure/acs-engine/blob/master/README.md#deployment-usage">here</a>. Note that a resource group should be created before executing the command.

Once the deployment to Azure finishes, verify that there are no failures in deploying any component inside resource group.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/ruazuredeployment1.png" alt="ruazuredeployment" width="639" height="758" class="alignnone size-full wp-image-1755" />

Now connect to ACS cluster as described <a target="_blank" href="https://docs.microsoft.com/en-us/azure/container-service/container-service-connect">here </a>and verify that server has <em>experimental</em> flag set as True.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/ruacsazure-1024x513.png" alt="ruacsazure" width="1024" height="513" class="alignnone size-large wp-image-1765" />

Now it is possible to use <em>docker deploy</em> command to deploy multi-container application. There is a very good <a target="_blank" href="https://docs.microsoft.com/en-us/azure/container-service/container-service-docker-swarm-setup-ci-cd">guidance </a>available on setting up CI/CD pipeline in VSTS (Visual Studio Team Services) for ACS with Docker Swarm. I followed instructions as given in that guidance <em>except </em>only 1 change. "<em>Run shell commands on remote machine</em>" task in the release tasks needs to be adjusted as below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/ruvsts-1024x466.png" alt="ruvsts" width="1024" height="466" class="alignnone size-large wp-image-1775" />

Once the shell script in the release task is successfully executed, it is reflected in the release log as shown below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/03/ruvstsrelease-1024x510.png" alt="ruvstsrelease" width="1024" height="510" class="alignnone size-large wp-image-1785" />

An important point to note here is that unlike <em>docker-compose up</em> command execution, which needs a <em>docker-compose down</em> command execution, which necessitates downtime, <em>docker deploy</em> command updates services (group of containers) without needing any downtime. Deploy configuration policy specified in the <em>docker-compose</em> file gives developers complete control over the update process.

It is now possible to implement <em>rolling updates</em> using docker deploy and docker-compose file on Azure Container Service (ACS) with Docker Swarm. Use this <a target="_blank" href="https://github.com/Mahesh-MSFT/ContainerRollingUpdate">github repository</a> for accessing code/docker files used for implementing rolling updates.]]></content:encoded>
    </item>
    <item>
      <title>Running SQL Server + ASP.Net Core in a container on Linux in Azure Container Service on Docker Swarm - Part 3</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/running-sql-server-asp-net-core-in-a-container-on-linux-in-azure-container-service-on-docker-swarm-part-3</link>
      <pubDate>Tue, 14 Feb 2017 12:55:58 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=1465</guid>
      <description><![CDATA[In previous post, I created an ASP.Net Core Container application interacting SQL Server Container....]]></description>
      <content:encoded><![CDATA[In <a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/02/14/running-sql-server-asp-net-core-in-a-container-on-linux-in-azure-container-service-on-docker-swarm-part-2/">previous post</a>, I created an ASP.Net Core Container application interacting SQL Server Container. In this post, I'll port this application to Azure. I am going to use Azure Container Service (ACS) with Docker Swarm as orchestrator.

Let me start by creating a ACS  cluster. I've followed instructions as described <a target="_blank" href="https://docs.microsoft.com/en-us/azure/container-service/container-service-deployment#create-a-cluster-by-using-the-azure-portal">here</a> . Point to remember while setting up this cluster to allow running SQL Server as Container is to choose VMs with at least 4GB ob RAM. This is a pre-requisite to run SQL Server Container using Docker.

With Docker Swarm as a container orchestrator, authoring microservice-style, multi-container application using <a target="_blank" href="https://docs.docker.com/compose/overview/">docker-compose</a> file is an easy process.  Earlier, as described, in <a href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/02/14/running-sql-server-asp-net-core-in-a-container-on-linux-in-azure-container-service-on-docker-swarm-part-1/">post 1</a>, a SQL Server Container image was created and pushed to Docker Hub. Similarly, in <a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/02/14/running-sql-server-asp-net-core-in-a-container-on-linux-in-azure-container-service-on-docker-swarm-part-2/">post 2</a>, an ASP.Net Core image was created and pushed to Docker Hub.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerhub2-1024x559.png" alt="sqldockerhub2" width="1024" height="559" class="alignnone size-large wp-image-1525" />

A docker-compose file will use these 2 images to deploy application in ACS. A network is also needed so that both these containers can run from within same network. docker-compose file looks something like below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockercompose1.png" alt="sqldockercompose" width="592" height="515" class="alignnone size-full wp-image-1535" />

This file has got 2 services and 1 network defined. Each service is created from their respective image. XXXweb service uses ASP.Net Core image. It uses port 8080 on the container host and 80 on the container itself. It has dependency on other service, named sqlinux. This service resides in network 2t (short-form for 2 tier!).

Other service is sqlinux. This service uses the SQL Server Container image. It runs on port 1433 on both container host as well as container. It also resides in network 2t.

Connect to ACS cluster from Windows machine as instructed <a target="_blank" href="https://docs.microsoft.com/en-us/azure/container-service/container-service-connect#connect-to-a-dcos-or-swarm-cluster">here</a>.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerputty.png" alt="sqldockerputty" width="452" height="437" class="alignnone size-full wp-image-1545" />

set the Docker Host variable on local Docker CLI environment using following command.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerhost.png" alt="sqldockerhost" width="468" height="39" class="alignnone size-full wp-image-1555" />

With Docker Host set, It is easy to interact with ACS cluster in Azure from local machine. Any command executed after setting up DOCKER_HOST, gets executed on ACS cluster. Refer <a target="_blank" href="https://blogs.msdn.microsoft.com/uk_faculty_connection/2016/09/23/getting-started-with-docker-and-container-services/">this </a>to understand more on setting up this variable.

Now navigate to the location where docker-compose file is available in command prompt. Execute following command to ensure that there are no services already running on ACS cluster.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockercommitps.png" alt="sqldockercommitps" width="353" height="70" class="alignnone size-full wp-image-1565" />

To deploy application, run following command.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockercomposeup.png" alt="sqldockercomposeup" width="496" height="80" class="alignnone size-full wp-image-1575" />

As can be see above, the instructions in docker-compose file are executed and 2 services and 1 network gets deployed to ACS. By running following command, verify if services are created as expected.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockercomposeps2.png" alt="sqldockercomposeps2" width="800" height="97" class="alignnone size-full wp-image-1585" />

This command shows state of the container and nodes along-with IP address where each service (container) is running. With the containers running as expected, its time to verify if the application is running. Grab the agent FQDN from the ACS dashboard.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockeracs-1024x426.png" alt="sqldockeracs" width="1024" height="426" class="alignnone size-large wp-image-1595" />

Append the port used for the ASP.Net Core app to it and hit enter.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerappinacs-1024x485.png" alt="sqldockerappinacs" width="1024" height="485" class="alignnone size-large wp-image-1605" />

Application is now running in ACS using Docker Swarm as an orchestrator.

This concludes this blog series on getting SQL Server and ASP.Net Core run in a container on Linux in Azure Container Service on Docker Swarm. Combination of SQL Server and ASP.Net Core is a very common to create enterprise applications. Being able to take this combination into world of containers is very important milestone. It is now easy to move such applications to either Linux or Windows platform. ACS offers even more productivity gain by abstracting away the infrastructure/orchestration concerns to deploy these application in Azure.]]></content:encoded>
    </item>
    <item>
      <title>Running SQL Server + ASP.Net Core in a container on Linux in Azure Container Service on Docker Swarm - Part 2</title>
      <link>https://docs.microsoft.com/archive/blogs/maheshkshirsagar/running-sql-server-asp-net-core-in-a-container-on-linux-in-azure-container-service-on-docker-swarm-part-2</link>
      <pubDate>Tue, 14 Feb 2017 12:55:43 GMT</pubDate>
      <dc:creator><![CDATA[Mahesh M Kshirsagar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/maheshkshirsagar/?p=1345</guid>
      <description><![CDATA[In previous post, we looked at how to create and run SQL Server Container. I'll build on that and...]]></description>
      <content:encoded><![CDATA[In <a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/02/14/running-sql-server-asp-net-core-in-a-container-on-linux-in-azure-container-service-on-docker-swarm-part-1/">previous post</a>, we looked at how to create and run SQL Server Container. I'll build on that and develop an ASP.Net Core application that can interact with database inside this container.

Start with File--&gt;New is Visual Studio 2015 and create an ASP.Net Core application. When all clicks finish, solution structure looks something like this.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerapp.png" alt="sqldockerapp" width="490" height="471" class="alignnone size-full wp-image-1355" />

Ignore the Hubs folder. As some may have guessed, I am trying to do some SignalR stuff. But you can start with a plain ASP.Net Core application as well.

Now to most important part, how to connect to SQL Server Container?

Connecting to a container is no different than connecting to a SQL Server. From a .Net Core application,a connectionstring needs to be defined and used with a Data Access Library. I am going to use .Net Core's native SQL Server client library. Any one of the many options listed <a target="_blank" href="https://blogs.msdn.microsoft.com/dotnet/2016/11/09/net-core-data-access/">here</a> can be used as well.

Use Nuget Package Manager from the Visual Studio Solution and pull <code>System.Data.SqlClient</code><span> package.</span>

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockernuget-1024x438.png" alt="sqldockernuget" width="1024" height="438" class="alignnone size-large wp-image-1365" />

Once package is registered, define connectionstring. As in the past, there are many different ways of defining connectionstring. In this post, I am going to define inside my SQL Data Access class.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerdbconnstring1-1024x20.png" alt="sqldockerdbconnstring" width="1024" height="20" class="alignnone size-large wp-image-1395" />

Important part of this connectionstring is the value of "Data Source". It should be the name as defined by using <strong>--name</strong> switch when the container was created. In short, it should be name of the SQL Server Container. Use strong password as opposed to the one used above.

Once connectionstring is defined, rest of queries can be implemented the way they are used to be defined. In my example, a INSERT block of C# code looks like below.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerc.png" alt="sqldockerc" width="964" height="421" class="alignnone size-full wp-image-1405" />

With the Docker Support in Visual Studio, It is possible to run application straight from within Container instead of running it from IIS Express.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockervs2.png" alt="sqldockervs2" width="690" height="229" class="alignnone size-full wp-image-1415" />

One can see the docker commands getting executed in the command prompt when you run the application from Visual Studio.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerrunningapp1-1024x601.png" alt="sqldockerrunningapp" width="1024" height="601" class="alignnone size-large wp-image-1426" />

We now have got both SQL Server as well as ASP.Net Core application running inside containers. I am running these containers on my local machine using "<a target="_blank" href="https://download.docker.com/win/beta/InstallDocker.msi">Docker For Windows</a>". I am simulating a Linux environment for these containers to run.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerlinux.png" alt="sqldockerlinux" width="253" height="243" class="alignnone size-full wp-image-1436" />

I can verify if the SQL Server Container is really able to store the data by querying table from SSMS.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerquery1.png" alt="sqldockerquery" width="653" height="367" class="alignnone size-full wp-image-1445" />

Surely, I do see data getting into table inside SQL Server Container. Just like we did in <a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/02/14/running-sql-server-asp-net-core-in-a-container-on-linux-in-azure-container-service-on-docker-swarm-part-1/">last post</a>, let's create and push the image for ASP.Net Core application. To create an image, use following docker file and put it in the same location as Visual Studio Solution file.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerappdockerfile-1024x242.png" alt="sqldockerappdockerfile" width="1024" height="242" class="alignnone size-large wp-image-1505" />

Run the following command to create docker image.

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/sqldockerappbuild.png" alt="sqldockerappbuild" width="803" height="36" class="alignnone size-full wp-image-1515" />

This image is now create on local machine. As in previous post, use docker push command to push it to  Docker Hub.

In the <a target="_blank" href="https://blogs.msdn.microsoft.com/maheshkshirsagar/2017/02/14/running-sql-server-asp-net-core-in-a-container-on-linux-in-azure-container-service-on-docker-swarm-part-3/">next post</a>, we'll take this set up and run it inside Azure Container Service using Docker Swarm as an orchestrator.]]></content:encoded>
    </item>
  </channel>
</rss>