{"id":206,"date":"2022-04-26T13:49:54","date_gmt":"2022-04-26T13:49:54","guid":{"rendered":"http:\/\/vargas-solar.com\/cloud-bigdata\/?page_id=206"},"modified":"2022-04-26T16:46:31","modified_gmt":"2022-04-26T16:46:31","slug":"quickstart-deploy-a-container-instance-in-azure-using-the-azure-cli","status":"publish","type":"page","link":"http:\/\/vargas-solar.com\/cloud-bigdata\/quickstart-deploy-a-container-instance-in-azure-using-the-azure-cli\/","title":{"rendered":"Quickstart: Deploy a container instance in Azure using the Azure CLI"},"content":{"rendered":"\n<p><strong>Objective<\/strong><\/p>\n\n\n\n<p>The general purpose of this lab exercise is to have a first experience in deploying an existing Docker container on Azure using its service, Azure CLI. The exercise is based on a QuickStart MS Azure tutorial.<\/p>\n\n\n\n<p>Therefore, in this exercise, we will use the Azure CLI to deploy an isolated Docker container and make its application available with a&nbsp;<strong><em>fully qualified domain name<\/em><\/strong>&nbsp;(FQDN). A few seconds after you execute a single deployment command, you can browse to the application running in the container.<\/p>\n\n\n\n<p><strong>Material<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Azure Account<\/li><li>Background general principle of container-based solutions for managing execution environments<\/li><li>Use the Bash environment in&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cloud-shell\/quickstart\">Azure Cloud Shell<\/a><a href=\"applewebdata:\/\/25E435FB-AC0C-4B7B-B7D3-F72B23953DEC#_ftn1\"><sup>[1]<\/sup><\/a>.&nbsp;<a href=\"https:\/\/shell.azure.com\/\"><\/a><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/portal.azure.com\/#cloudshell\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-content\/uploads\/sites\/46\/2022\/04\/image.png\" alt=\"\" class=\"wp-image-207\" width=\"342\" height=\"52\" srcset=\"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-content\/uploads\/sites\/46\/2022\/04\/image.png 342w, http:\/\/vargas-solar.com\/cloud-bigdata\/wp-content\/uploads\/sites\/46\/2022\/04\/image-300x46.png 300w\" sizes=\"auto, (max-width: 342px) 100vw, 342px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>To Do<\/strong><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong>Create a resource group<\/strong><\/h2>\n\n\n\n<p>Azure container instances, like all Azure resources, must be deployed into a resource group. Recall that&nbsp;<strong>resource groups<\/strong>&nbsp;allow you to organize and manage related Azure resources.<\/p>\n\n\n\n<p>First, create a resource group named&nbsp;<em>myResourceGroup<\/em>&nbsp;in the&nbsp;<em>eastus<\/em>&nbsp;location with the following&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/cli\/azure\/group#az_group_create\">az group create<\/a>&nbsp;command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">az group create --name myResourceGroup --location eastus<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong>Create a container<\/strong><\/h2>\n\n\n\n<p>Now that you have a resource group, you can run a container in Azure. To create a container instance with the Azure CLI:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>provide a resource group name, container instance name, and&nbsp;<\/li><li>Docker container image to the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/cli\/azure\/container#az_container_create\">az container create<\/a>&nbsp;command.&nbsp;<\/li><\/ul>\n\n\n\n<p>In this quickstart, you:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Use the public&nbsp;<code>mcr.microsoft.com\/azuredocs\/aci-helloworld&nbsp;<\/code>image. This image packages a simple web app written in Node.js that serves a static HTML page.<\/li><li>Deploy a container with a DNS name label so that the web app is publicly reachable<a href=\"applewebdata:\/\/25E435FB-AC0C-4B7B-B7D3-F72B23953DEC#_ftn2\"><sup>[2]<\/sup><\/a>.<\/li><\/ul>\n\n\n\n<p>Execute a command similar to the following to start a container instance.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Set a&nbsp;<code>--dns-name-label<\/code>&nbsp;value that&#8217;s unique within the Azure region where you create the instance.&nbsp;<\/li><li>If you receive a &#8220;DNS name label not available&#8221; error message, try a different DNS name label.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">az container create --resource-group myResourceGroup --name mycontainer --image mcr.microsoft.com\/azuredocs\/aci-helloworld --dns-name-label lis4112 --ports 80<\/pre>\n\n\n\n<p>Within a few seconds, you should get a response from the Azure CLI indicating that the deployment has been completed. Check its status with the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/cli\/azure\/container#az_container_show\">az container show<\/a>&nbsp;command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">az container show --resource-group myResourceGroup --name mycontainer --query \"{FQDN:ipAddress.fqdn,ProvisioningState:provisioningState}\" --out table<\/pre>\n\n\n\n<p>If the container&#8217;s&nbsp;ProvisioningState&nbsp;is&nbsp;<strong>Succeeded<\/strong>, go to its FQDN in your browser. If you see a web page like the following, congratulations! You&#8217;ve successfully deployed an application running in a Docker container to Azure.<\/p>\n\n\n\n<p>If at first the application isn&#8217;t displayed, you might need to wait a few seconds while DNS propagates, then try refreshing your browser.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3.&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong>Pull the container logs<\/strong><\/h2>\n\n\n\n<p>When you need to troubleshoot a container or the application it runs (or just see its output), start by viewing the container instance&#8217;s logs.<\/p>\n\n\n\n<p>Pull the container instance logs with the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/cli\/azure\/container#az_container_logs\">az container logs<\/a>&nbsp;command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">az container logs --resource-group myResourceGroup --name mycontainer<\/pre>\n\n\n\n<p>The output displays the logs for the container and should show the HTTP GET requests generated when you viewed the application in your browser.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4.&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong>Attach output streams<\/strong><\/h2>\n\n\n\n<p>In addition to viewing the logs, you can attach your local standard out and standard error streams to that of the container.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>First, execute the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/cli\/azure\/container#az_container_attach\">az container attach<\/a>&nbsp;command to attach your local console to the container&#8217;s output streams.<\/li><li>Once attached, refresh your browser a few times to generate some additional output. When you&#8217;re done, detach your console with&nbsp;Control+C.&nbsp;<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5.&nbsp;&nbsp;&nbsp;&nbsp;<\/strong><strong>Clean up resources<\/strong><\/h2>\n\n\n\n<p>When you&#8217;re done with the container, remove it using the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/cli\/azure\/container#az_container_delete\">az container delete<\/a>&nbsp;command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">az container delete --resource-group myResourceGroup --name mycontainer<\/pre>\n\n\n\n<p>To verify that the container has been deleted, execute the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/cli\/azure\/container#az-container-list\">az container list<\/a>&nbsp;command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">az container list --resource-group myResourceGroup --output table<\/pre>\n\n\n\n<p>The&nbsp;<strong>mycontainer<\/strong>&nbsp;container should not appear in the command&#8217;s output. If you have no other containers in the resource group, no output is displayed.<\/p>\n\n\n\n<p>If you&#8217;re done with the\u00a0<em>myResourceGroup<\/em>\u00a0resource group and all the resources it contains, deletes it with the\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/cli\/azure\/group#az_group_delete\">az group delete<\/a>\u00a0command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">az group delete --name myResourceGroup<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><a href=\"applewebdata:\/\/25E435FB-AC0C-4B7B-B7D3-F72B23953DEC#_ftnref1\"><sup>[1]<\/sup><\/a>&nbsp;For more information, see&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cloud-shell\/quickstart\">Azure Cloud Shell Quickstart &#8211; Bash<\/a>.<\/p>\n\n\n\n<p><a href=\"applewebdata:\/\/25E435FB-AC0C-4B7B-B7D3-F72B23953DEC#_ftnref2\"><sup>[2]<\/sup><\/a>&nbsp;You can expose your containers to the internet by specifying one or more ports to open, a DNS name label, or both.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Objective The general purpose of this lab exercise is to have a first experience in deploying an existing Docker container on Azure using its service, Azure CLI. The exercise is based on a QuickStart MS Azure tutorial. Therefore, in this exercise, we will use the Azure CLI to deploy an isolated Docker container and make [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"page-templates\/full-width.php","meta":{"footnotes":""},"class_list":["post-206","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-json\/wp\/v2\/pages\/206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-json\/wp\/v2\/comments?post=206"}],"version-history":[{"count":4,"href":"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-json\/wp\/v2\/pages\/206\/revisions"}],"predecessor-version":[{"id":214,"href":"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-json\/wp\/v2\/pages\/206\/revisions\/214"}],"wp:attachment":[{"href":"http:\/\/vargas-solar.com\/cloud-bigdata\/wp-json\/wp\/v2\/media?parent=206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}