<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: David Cobb</title>
    <description>The latest articles on Forem by David Cobb (@dave007).</description>
    <link>https://forem.com/dave007</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F98730%2F5e057932-0e7e-4ba7-8680-a1341ab0c7ed.png</url>
      <title>Forem: David Cobb</title>
      <link>https://forem.com/dave007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dave007"/>
    <language>en</language>
    <item>
      <title>Deploy a Serverless ASP.NET App to Azure Container Instances from Cloud Shell</title>
      <dc:creator>David Cobb</dc:creator>
      <pubDate>Wed, 26 Feb 2020 09:40:38 +0000</pubDate>
      <link>https://forem.com/cloudskills/deploy-a-serverless-asp-net-app-to-azure-container-instances-from-cloud-shell-535j</link>
      <guid>https://forem.com/cloudskills/deploy-a-serverless-asp-net-app-to-azure-container-instances-from-cloud-shell-535j</guid>
      <description>&lt;h1&gt;
  
  
  Table of Contents
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What You Will Learn&lt;/li&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Step 1 - Get Into Azure Cloud Shell &amp;amp; Editor&lt;/li&gt;
&lt;li&gt;Step 2 - Deploy Azure Container Registry with an ARM Template&lt;/li&gt;
&lt;li&gt;Step 3 - Create a .NET Core Web Application&lt;/li&gt;
&lt;li&gt;Step 4 - Create a Docker File&lt;/li&gt;
&lt;li&gt;Step 5 - Build and Push a Docker Image to Azure Container Registry&lt;/li&gt;
&lt;li&gt;Step 6 - Prepare to Deploy Your Docker Image as a Serverless Container&lt;/li&gt;
&lt;li&gt;Step 7 - Deploy Your Container, Review and Test&lt;/li&gt;
&lt;li&gt;Step 8 - Clean Up&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Keeping up with cloud technology is a continual challenge that requires continuous learning by cloud builders. As we seek to stay current with the evolution of new cloud technologies, we must decide which tools to invest our time in, choosing the most powerful and flexible tools available to maximize our effectiveness and time investment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1BN3nYVI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o8lksnr8r1twe55anlg6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1BN3nYVI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o8lksnr8r1twe55anlg6.gif" alt="Azure Cloud Shell"&gt;&lt;/a&gt; &lt;strong&gt;Azure Cloud Shell&lt;/strong&gt; is one such powerful tool. Learn Azure Cloud Shell and you unlock the full capability of the Azure cloud, with tools built in including Code Editor, Azure PowerShell and CLI, .NET Core and Docker.&lt;/p&gt;

&lt;p&gt;This tutorial introduces you to these tools very rapidly, and toward a very useful goal. You will create, build and publish a .NET Core application, inside a Docker container, to Azure in a Serverless deployment model.&lt;/p&gt;

&lt;h2&gt;
  
  
  What You Will Learn &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use the &lt;strong&gt;&lt;a href="https://docs.microsoft.com/en-us/azure/cloud-shell/using-cloud-shell-editor"&gt;Azure Cloud Shell Editor&lt;/a&gt;&lt;/strong&gt; to create a PowerShell script that sets variables for the tutorial.&lt;/li&gt;
&lt;li&gt;Deploy infrastructure as code using a Quickstart &lt;strong&gt;&lt;a href="https://azure.microsoft.com/en-us/resources/templates/"&gt;ARM Template&lt;/a&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Create an &lt;strong&gt;ASP.NET Core&lt;/strong&gt; application with the &lt;a href="https://docs.microsoft.com/en-us/dotnet/core/tools/?tabs=netcore2x"&gt;&lt;strong&gt;.NET Core CLI&lt;/strong&gt;&lt;/a&gt; with no development environment setup.&lt;/li&gt;
&lt;li&gt;Use the &lt;strong&gt;&lt;a href="https://docs.microsoft.com/en-us/azure/cloud-shell/using-cloud-shell-editor"&gt;Azure Cloud Shell Editor&lt;/a&gt;&lt;/strong&gt; to create a docker file.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;a href="https://github.com/Azure/azure-cli"&gt;Azure CLI&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;az acr build&lt;/em&gt; command to build and push a docker image to your &lt;strong&gt;&lt;a href="https://azure.microsoft.com/en-us/services/container-registry/"&gt;Azure Container Registry (ACR)&lt;/a&gt;&lt;/strong&gt; with no tooling setup.&lt;/li&gt;
&lt;li&gt;Deploy a Docker image as a serverless container to &lt;strong&gt;&lt;a href="https://docs.microsoft.com/en-us/azure/container-instances/container-instances-overview"&gt;Azure Container Instances&lt;/a&gt;&lt;/strong&gt; with no infrastructure setup.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;a href="https://docs.microsoft.com/en-us/azure/cloud-shell/overview"&gt;Azure Cloud Shell&lt;/a&gt;&lt;/strong&gt; with &lt;strong&gt;&lt;a href="https://docs.microsoft.com/en-us/powershell/azure/get-started-azureps?view=azps-3.4.0"&gt;Azure PowerShell&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://github.com/Azure/azure-cli"&gt;Azure CLI&lt;/a&gt;&lt;/strong&gt; command line interface as powerful tools in infrastructure and application development and deployment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prerequisites &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In order to follow this guide, you will need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An active Azure subscription&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1 - Get Into Azure Cloud Shell &amp;amp; Editor &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Log into your Azure account at &lt;a href="https://portal.azure.com"&gt;portal.azure.com&lt;/a&gt;, then click the &lt;strong&gt;Cloud Shell&lt;/strong&gt; icon in the top nav bar to enter the &lt;strong&gt;Azure Cloud Shell&lt;/strong&gt;. If this is your first time in the shell you will need to create your cloud drive storage. First time users may refer to &lt;a href="https://www.youtube.com/watch?v=HBKm1-_kWKg"&gt;David Lamb's Azure Cloud Shell tutorial (1.5 min)&lt;/a&gt; for guidance. Choose &lt;strong&gt;PowerShell&lt;/strong&gt; as your shell type on the dropdown to the top left.&lt;/p&gt;

&lt;p&gt;During the tutorial you may want to maximize the cloud shell window using the maximize button at the upper right. Click that button again to restore the cloud shell window back down to the original size.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ugwZ0uDJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sr974thu26bpnlsj8qcr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ugwZ0uDJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sr974thu26bpnlsj8qcr.png" alt="Cloud Shell maximize/restore button"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before continuing, note the prompt for Azure Cloud Shell, &lt;code&gt;PS Azure:\&amp;gt;&lt;/code&gt; , indicates your location as &lt;code&gt;Azure:\&lt;/code&gt;. You can imagine this as the root directory of a file server, but instead of files, it holds hierarchy of &lt;em&gt;all your Azure resources&lt;/em&gt;. You can type &lt;code&gt;Get-ChildItem&lt;/code&gt; to see your subscription(s), and use &lt;code&gt;Set-Location &amp;lt;TAB&amp;gt;&lt;/code&gt; to begin navigating that hierarchy. &lt;em&gt;But that is the subject of another tutorial.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you try to use the code editor to save files in this starting location of &lt;code&gt;Azure:\&lt;/code&gt;, you will get an error. Instead, type &lt;code&gt;cd ~\clouddrive&lt;/code&gt; (that starts with the tilde character (~) at the top right of your keyboard, a symbol for your home directory) to navigate to your clouddrive, and type &lt;code&gt;pwd&lt;/code&gt; (an alias of &lt;code&gt;Get-ChildItem&lt;/code&gt;) to see your current location in the drive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~\clouddrive
pwd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--axtZRfjY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cgz5chjhjporju05sl0c.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--axtZRfjY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cgz5chjhjporju05sl0c.gif" alt="cd clouddrive"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now type &lt;code&gt;code mySettings.ps1&lt;/code&gt; to launch the cloud shell editor in your &lt;code&gt;~\clouddrive&lt;/code&gt; folder and edit the new PowerShell script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;code mySettings.ps1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Use the editor to paste in the content of the powershell script below &lt;strong&gt;using &lt;em&gt;Control-V&lt;/em&gt; instead of right-click&lt;/strong&gt;. Customize the values, then click the ellipsis &lt;strong&gt;(...)&lt;/strong&gt; in the upper right corner of the cloud shell editor to save, then close editor.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;NOTE:&lt;/strong&gt; Globally Unique Names
&lt;/h3&gt;

&lt;p&gt;Naming things in Azure can be tricky, with different naming rules for different types of resources.&lt;br&gt;
For simplicity, &lt;em&gt;stick with lowercase letters and numbers.&lt;/em&gt;&lt;br&gt;
Certain values must be GLOBALLY UNIQUE, like registry names and domain names,&lt;br&gt;
so something like 'DaveApp' doesn't usually work. It is a good idea to&lt;br&gt;
append numbers to a name, like &lt;em&gt;daveawesomedockerapp0123&lt;/em&gt; to create a unique name easily.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Your personal settings, customize these using lowercase letters and numbers
$myLocationName = 'eastus2'                 # An Azure region close to you, 'Get-AzLocation' to list them all
$myRGName       = 'containerdemo-rg'        # Resource group to contain this demo
$myWebAppName   = 'davewebappdocker0123'    # Name for your web app
$myRegistryName = 'daveregistry0123'        # GLOBALLY UNIQUE name for your container registry
$myDNSName      = 'daveawesomedockerapp0123'# GLOBALLY UNIQUE dns name, will be prepended to .azurecontainer.io
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now &lt;strong&gt;&lt;a href="https://ss64.com/ps/source.html"&gt;dot source&lt;/a&gt;&lt;/strong&gt; the script by running &lt;code&gt;. ./mySettings.ps1&lt;/code&gt;. This will define the variables you'll need for this tutorial in this PowerShell session.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MQSqAr49--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b2k9pd5v5dhohmvrcm3m.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MQSqAr49--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b2k9pd5v5dhohmvrcm3m.gif" alt="Cloud Shell Code Editor mySettings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;WARNING:&lt;/strong&gt; If Cloud Shell session is interrupted, restart the session and re-run this script line
&lt;/h3&gt;

&lt;p&gt;The success of the tutorial depends on the variables above. If for some reason your&lt;br&gt;
&lt;strong&gt;Azure Cloud Shell&lt;/strong&gt; &lt;a href="https://docs.microsoft.com/en-us/azure/cloud-shell/limitations#system-state-and-persistence"&gt;session is interrupted&lt;/a&gt;, (perhaps with an &lt;strong&gt;access token expiry error&lt;/strong&gt;, or &lt;strong&gt;unauthorized error&lt;/strong&gt;),&lt;br&gt;
You &lt;strong&gt;may&lt;/strong&gt; need to restart your session with the &lt;strong&gt;Restart Cloud Shell&lt;/strong&gt; button at top of shell window.&lt;br&gt;
Once you resume your session, remember to run &lt;code&gt;cd ~\clouddrive&lt;/code&gt; since you can't save files in the &lt;code&gt;Azure:\&lt;/code&gt; location, then run &lt;code&gt;. ./mySettings.ps1&lt;/code&gt; again.&lt;br&gt;
This will ensure you can continue the tutorial.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AWHGAj7w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i7854puakbscazetdl1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AWHGAj7w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i7854puakbscazetdl1w.png" alt="Restart Cloud Shell"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 2 - Deploy Azure Container Registry with an ARM Template &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Next, you use &lt;code&gt;New-AzResourceGroup&lt;/code&gt; to create a resource group for this demo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;New-AzResourceGroup -Name $myRGName -Location $myLocationName
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you deploy your &lt;strong&gt;Azure Container Registry&lt;/strong&gt; (ACR), once you have tested the name to ensure uniqueness.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Test-AzContainerRegistryNameAvailability -Name $myRegistryName
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;WARNING:&lt;/strong&gt; Ensure unique name for your Azure Container Registry
&lt;/h3&gt;

&lt;p&gt;If &lt;code&gt;NameAvailable&lt;/code&gt; is not &lt;code&gt;True&lt;/code&gt; in the result, redefine your registry name by running the command&lt;br&gt;
&lt;code&gt;$myRegistryName = 'mynewregname001'&lt;/code&gt; and pressing &lt;strong&gt;enter&lt;/strong&gt;. Then press &lt;strong&gt;UP-Arrow&lt;/strong&gt; twice, scrolling through &amp;gt; command history to display the &lt;code&gt;Test-AzContainerRegistryNameAvailability&lt;/code&gt; command, then press &lt;strong&gt;enter&lt;/strong&gt; to&lt;br&gt;
run it again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With your registry name verified as unique, you deploy a Quickstart &lt;strong&gt;&lt;a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/overview"&gt;Azure Resource Manager Template (ARM Template)&lt;/a&gt;&lt;/strong&gt; from Microsoft's GitHub repository to create your &lt;strong&gt;Azure Container Registry&lt;/strong&gt;. This ARM Template is a small JSON file that describes the resource to deploy, and you can &lt;a href="https://raw.githubusercontent.com/microsoft/devops-project-samples/master/dotnet/aspnetcore/kubernetes/ArmTemplates/containerRegistry-template.json"&gt;view the JSON for the ARM Template you will use here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Review and run the code below, which will set&lt;code&gt;$containerRegistryTemplateUrl&lt;/code&gt; to the URL for this ARM Template that will define your &lt;strong&gt;Azure Container Registry&lt;/strong&gt; resource. Then you define &lt;code&gt;$containerRegistryParams&lt;/code&gt; as a &lt;a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_hash_tables?view=powershell-7"&gt;hash table&lt;/a&gt; to pass the parameters the template needs. Then you execute &lt;code&gt;New-AZResourceGroupDeployment&lt;/code&gt; to deploy the ARM template.&lt;/p&gt;

&lt;p&gt;Paste the code block below into the &lt;strong&gt;Azure Cloud Shell&lt;/strong&gt; to deploy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $containerRegistryTemplateUrl = 'https://raw.githubusercontent.com/microsoft/devops-project-samples/master/dotnet/aspnetcore/kubernetes/ArmTemplates/containerRegistry-template.json'
    $containerRegistryParams = @{
        registryName        = $myRegistryName
        registryLocation    = $myLocationName
    }
    New-AZResourceGroupDeployment -Name "$myRGName-ACR-Deployment" -ResourceGroupName $myRGName -TemplateUri $containerRegistryTemplateUrl -TemplateParameterObject $containerRegistryParams

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If all is well, the &lt;code&gt;ProvisioningState&lt;/code&gt; value should display &lt;code&gt;Succeeded&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IO6Bwe2r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tbjb41rhwuk2x29fmmi7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IO6Bwe2r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tbjb41rhwuk2x29fmmi7.png" alt="result of ARM template deployment"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;NOTE:&lt;/strong&gt; Troubleshoot using Activity Log
&lt;/h3&gt;

&lt;p&gt;If at first you don't succeed, review the &lt;strong&gt;Activity Log&lt;/strong&gt;&lt;br&gt;
under &lt;strong&gt;Notifications&lt;/strong&gt; in the portal.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6TMynzNE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gr5vpib0fu3ospl2mg0l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6TMynzNE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gr5vpib0fu3ospl2mg0l.png" alt="Troubleshooting ARM template deployments"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Next you use the &lt;code&gt;Get-AZContainerRegistry&lt;/code&gt; command to store your &lt;strong&gt;Azure Container Registry&lt;/strong&gt; (ACR) information in a variable to refer to it later in the tutorial.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$myACR = Get-AzContainerRegistry -ResourceGroupName $myRGName
$myACR
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Js4yRJpL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zo4gnkojdvl2gl9ij4s7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Js4yRJpL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zo4gnkojdvl2gl9ij4s7.png" alt="Result of `Get-AzContainerRegistry`"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 - Create a .NET Core Web Application &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Begin from your clouddrive folder. Type &lt;code&gt;pwd&lt;/code&gt; to verify your current location.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~\clouddrive
pwd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create a new folder &lt;code&gt;docker-working&lt;/code&gt; and &lt;code&gt;cd&lt;/code&gt; into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir docker-working
cd docker-working
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TylEdPSA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/quqy5ktj4wihdvo3pzfw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TylEdPSA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/quqy5ktj4wihdvo3pzfw.png" alt="docker working directory"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you will build a new .NET Core web application using the &lt;code&gt;dotnet&lt;/code&gt; command line tool.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;NOTE:&lt;/strong&gt; Alternately build an existing Asp.NET Core project
&lt;/h3&gt;

&lt;p&gt;Alternately, instead of creating a new application, you could use &lt;code&gt;git clone&lt;/code&gt;&lt;br&gt;
to work with an existing application in GitHub. &lt;em&gt;This is another topic for a future tutorial.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Paste the next 3 lines to create your new web app and its dependencies, then use &lt;code&gt;cd&lt;/code&gt; to the new directory. You can run &lt;code&gt;ls&lt;/code&gt; to inspect the contents of the published folder, or &lt;code&gt;gci -r&lt;/code&gt;, and alias to &lt;code&gt;Get-ChildItem -Recurse&lt;/code&gt; and see the entire contents of the application folder hierarchy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet new webapp -o mywebapp
cd mywebapp

pwd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---yJ--Bxf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gvo408z85cs64wv4mric.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---yJ--Bxf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gvo408z85cs64wv4mric.png" alt="Results of dotnet new"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 - Create a Docker File &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You can type &lt;code&gt;cls&lt;/code&gt; any time to clear the screen, then type &lt;code&gt;code DOCKERFILE&lt;/code&gt; from within your new webapp folder to launch the cloud shell editor and create a new file named DOCKERFILE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;code DOCKERFILE
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Paste the following code block into the DOCKERFILE &lt;strong&gt;using &lt;em&gt;Shift-Insert&lt;/em&gt; or &lt;em&gt;Command-V&lt;/em&gt; (macOS) instead of right-click&lt;/strong&gt;, then click the ellipsis &lt;strong&gt;(...)&lt;/strong&gt; in the upper right corner of the cloud shell editor to save, then close editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "mywebapp.dll"]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dMbt_ijI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cr8kew4qlesevv4jcrgi.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dMbt_ijI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cr8kew4qlesevv4jcrgi.gif" alt="Using Code Editor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;NOTE:&lt;/strong&gt; Docker Syntax
&lt;/h3&gt;

&lt;p&gt;The dockerfile commands describe how to build and run the .NET Core web application created in Step 3 as a container.&lt;br&gt;
&lt;em&gt;Docker syntax is another topic for a future tutorial.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 5 - Build and Push a Docker Image to Azure Container Registry &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;First, run &lt;code&gt;pwd&lt;/code&gt; to ensure you're in the root of the webapp folder, then use the &lt;a href="https://docs.microsoft.com/en-us/cli/azure/acr?view=azure-cli-latest#az-acr-build"&gt;Azure CLI command &lt;code&gt;az acr build&lt;/code&gt;&lt;/a&gt; shown below (including the period at the end) to build the docker image. This is a powerful tool that enables you to build docker images and push to a repository in one step, all without setting up or running docker on your workstation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;NOTE:&lt;/strong&gt;  Azure CLI in PowerShell
&lt;/h3&gt;

&lt;p&gt;You can use Azure CLI commands in Bash or PowerShell sessions.&lt;br&gt;
Sometimes Azure CLI is more terse than PowerShell, or new features may get support in Azure CLI before PowerShell, so use what gets the job done.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;az acr build --registry $myACR.Name --image mywebapp:v1 .
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cST6LDbo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f28eyc2cne3p2y3wyqro.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cST6LDbo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f28eyc2cne3p2y3wyqro.gif" alt="Result of az acr build"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;WARNING:&lt;/strong&gt; Troubleshooting
&lt;/h3&gt;

&lt;p&gt;If you get an error on this step, possibly your Azure Cloud Shell &lt;a href="https://docs.microsoft.com/en-us/azure/cloud-shell/limitations#system-state-and-persistence"&gt;session is interrupted&lt;/a&gt;,&lt;br&gt;
you can repeat the code from above to define variables including those from the &lt;code&gt;. ./mySettings.ps1&lt;/code&gt; command and &lt;code&gt;$myACR&lt;/code&gt; then try it again:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# If Cloud Shell Session was interrupted, run to redefine your variables
cd ~/clouddrive
. ./mySettings.ps1
$myACR = Get-AzContainerRegistry -ResourceGroupName $myRGName
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6 - Prepare to Deploy Your Docker Image as a Serverless Container &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Gather information needed for deploying to &lt;strong&gt;Azure Container Instances&lt;/strong&gt; using the &lt;code&gt;New-AzContainerGroup&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;First, get your container repository from your container registry (ACR):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[array]$myRepositories = az acr repository list --name $myACR.Name | ConvertFrom-Json
$myRepository = $myRepositories[0]
$myRepository
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, get the latest tag from the image in your container repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$myImageTags = az acr repository show-tags --name $myACR.Name --repository $myRepository --detail --orderby time_desc | ConvertFrom-JSON
$myImageTag = $myImageTags[0]
$myImageTag.name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now build the path to the docker image you will deploy. Note the format is a DNS name that points to your &lt;strong&gt;Azure Container Registry&lt;/strong&gt;, followed by the repository (&lt;strong&gt;mywebapp&lt;/strong&gt;) and the tag (&lt;strong&gt;v1&lt;/strong&gt;.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$myDockerImagePath = "$($myACR.LoginServer)/$($myRepository):$($myImageTag.name)"
$myDockerImagePath
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Since this is a private container registry, you need to provide credentials. Use the &lt;code&gt;Get-AzContainerRegistryCredential&lt;/code&gt; command along with the &lt;code&gt;PSCredential&lt;/code&gt; type accelerator to create the credential object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$regCred = Get-AzContainerRegistryCredential -ResourceGroupName $myRGName  -Name $myACR.Name
$PSCred = [PSCredential]::New($regCred.Username, (ConvertTo-SecureString $regCred.Password -AsPlainText -Force)) # Type accelerators rule!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this &lt;em&gt;optional&lt;/em&gt; step, you create a hash table to define resource tags, these are useful for keeping track of your Azure resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$tags = @{
    Env = 'Dev'
    Purpose = "Use Azure PowerShell command 'New-AzContainerGroup' to deploy containers from your Azure container registry easily!"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now set up parameters in a hash table to pass to the command via &lt;a href="https://devblogs.microsoft.com/scripting/use-splatting-to-simplify-your-powershell-scripts/"&gt;Splatting&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ContainerGroupArguments = @{
    ResourceGroupName   = $myRGName
    Name                = "$myWebAppName-cg"    #build container group name from the webapp name
    Image               = $myDockerImagePath
    IpAddressType       = 'Public'
    DNSNameLabel        = $myDNSName
    Port                = 80                    #optional
    RegistryCredential  = $PSCred               #required if this is NOT a public docker registry
    IdentityType        = 'SystemAssigned'      #optional, but useful for a future tutorial
    Tag                 = $tags                 #optional uses hash table defined above
    Debug               = $true                 #optional but very interesting to see the debug output
    }

# review contents of the parameter hash table

$ContainerGroupArguments
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 7 - Deploy Your Container, Review and Test &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You are ready to deploy your new Azure container group by running the &lt;code&gt;New-AzContainerGroup&lt;/code&gt; command. Since it has a &lt;code&gt;Debug&lt;/code&gt; flag in the arguments, you will need to confirm the execution. Review the debug output in yellow for an interesting peek under the hood of Azure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$newACG = New-AzContainerGroup @ContainerGroupArguments
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After you confirm the execution and it completes, review the Debug output, then inspect your container group via the &lt;code&gt;$newACG&lt;/code&gt; variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$newACG | Get-Member
$newACG | Select-Object *
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dU5DGml0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i0wy97nnk86nh0hkierp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dU5DGml0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i0wy97nnk86nh0hkierp.png" alt="Inspect ACG Object"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;FQDN&lt;/code&gt; property is the &lt;em&gt;Fully Qualified Domain Name&lt;/em&gt; of your containerized application. Paste this into your favorite browser to see your new ASP.NET Core serverless containerized web application in action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Write-Output " Paste    $($newACG.FQDN)  into your favorite web browser"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Browse your newly deployed Azure serverless Docker containerized ASP.NET Core web application!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYBMACDe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/496pwwrslwbx4z3vl7wr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYBMACDe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/496pwwrslwbx4z3vl7wr.png" alt="Browse WebApp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After browsing the web application, review the log of your container instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Get-AzContainerInstanceLog  -ResourceGroupName $myRGName -ContainerGroupName $ContainerGroupArguments.Name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 8 - Clean Up &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The resources for this tutorial are very cost effective. Even so, it's a good idea to clean up once completed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Remove-AzResourceGroup -ResourceGroupName $myRGName -Force
cd ~/clouddrive
rm ./docker-working/ -r
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You have used &lt;strong&gt;Azure Cloud Shell&lt;/strong&gt; on a whirlwind tour of powerful tools and features it contains.&lt;br&gt;
You have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Created an &lt;strong&gt;ASP.NET Core&lt;/strong&gt; web application&lt;/li&gt;
&lt;li&gt;Built a &lt;strong&gt;Docker&lt;/strong&gt; container&lt;/li&gt;
&lt;li&gt;Pushed that container to a repository image in your private &lt;strong&gt;Azure Container Registry&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Deployed that image to &lt;strong&gt;Azure Container Instances&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Along the way you explored features of &lt;strong&gt;Azure Cloud Shell&lt;/strong&gt; including &lt;strong&gt;Azure PowerShell&lt;/strong&gt; and &lt;strong&gt;Azure CLI&lt;/strong&gt;, &lt;strong&gt;Azure Resource Manager&lt;/strong&gt; templates, the &lt;strong&gt;Cloud Shell Code Editor&lt;/strong&gt;, and the &lt;strong&gt;.NET Core CLI.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I hope this tutorial encourages you to explore Azure with the Cloud Shell, and makes you a more effective cloud builder!&lt;/p&gt;

</description>
      <category>azure</category>
      <category>powershell</category>
      <category>cli</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
