Docker in Azure (ACI): A Getting Started Tutorial

choubertsprojects

The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

Docker for Azure is a new managed service designed to simplify the development of container-based applications using Microsoft’s cloud platform. Learn how to use Docker in Azure and get started with your first application.

The “docker for azure tutorial” is a blog that will help you get started with Docker in Azure. The blog covers topics like how to install Docker and what it takes to run a container.

Docker in Azure (ACI): A Getting Started Tutorial

This ATA Project will provide you an overview of how Docker works on Azure. You’ll learn about Microsoft’s Azure Container Instance (ACI) service in this Azure Docker lesson.

Azure Container Instance is an Azure Docker-hosted Kubernetes cluster. It enables you to execute any Docker image (on Windows or Linux) as a container. Each Azure Docker container operates independently, with its own CPU and memory resources.

Based on a sample ASP.NET container image from Microsoft on the Azure public cloud, you’ll learn how to deploy and operate your first Azure Container Instance in this project.

You’ll have an ASP.NET website operating in a Docker container hosted by the Azure Container Instance service by the Conclusion of this project.

Requirements for the Environment and Knowledge

You should have the following to get the most out of this Azure Docker tutorial:

  1. Docker Desktop is installed on a local Windows 10 client.
  2. A Microsoft Azure account is required.
  3. An Azure account having the ability to deploy a container to Azure Container Registry.
  4. Installed the Windows Azure CLI. The command line will be your teacher.
  5. A basic grasp of Docker and containers.
  6. An official Docker ID.

You may always choose another container image from the Docker Hub if you don’t like the example given in this Azure Docker tutorial.

Let’s get started on this Project without further ado!

Docker Container Management

Always verify that the Docker Engine is operating to save annoyance later when anything fails. To do so, run docker info from a command prompt or PowerShell session.

The sort of output you should get is shown below.

Examining information about the Docker installation on the local machineExamining information about the Docker installation on the local machine

Run docker run hello-world to verify that a Docker container has been started. The docker command does a couple things behind the scenes:

  1. Looks for a hello-word container on your Windows 10 PC locally.
  2. If the container with the name hello-world is not discovered, it searches the public Docker Hub repository for the newest version.
  3. After finding the container, it is downloaded from the Docker Hub repository.
  4. The container is started when it has been downloaded, and it follows the starting instructions in the image it is utilizing.

Below are some examples of output.

Obtain a sample hello-world is a Docker container.Obtain a sample hello-world is a Docker container.

Creating an ASP.NET Container in Practice

Now that you know how to download and run a Docker container, go ahead and download and run the container for this project. This Docker container contains an image of an ASP.Net Core web app.

Run the following command to get the image for this Azure Docker tutorial:

> docker run –name aspnetcore_sample –rm -it -p 8000:80 mcr.microsoft.com/dotnet/core/samples:aspnetapp

The following is what this command does:

  1. Because the Docker image isn’t accessible locally, Docker uses another public container registry provided by Microsoft, mcr.microsoft.com, to get a container named aspnetapp from the dotnet/core/samples directory. Microsoft maintains the mcr.microsoft.com container registry, which is identical to the public Docker Hub but solely contains Microsoft container images.
  2. The container is started on your local PC.
  3. (-p 8000:80) — Maps the container’s listening TCP port 80 to TCP port 8000. This enables you to use port 8000 to visit the web app locally.
  4. (-it) – The container will start interactively, which means you will be taken into the terminal right away.
  5. (—rm) – The container will be deleted when it is stopped.

The output you may anticipate is shown below.

Obtaining a Microsoft container instanceObtaining a Microsoft container instance

6. Go to http://localhost:8000 in your browser to connect to this running container application. Check out the ASP.Net example web app.

A sample ASP.NET web applicationA sample ASP.NET web application

Instance of Azure Container Registry (ACR) creation

Once you’ve downloaded the ASP.NET container to your local computer, you can use ACI to migrate it to Azure Docker hosting and execute it on Azure. We’ll do this by submitting the example container to Azure Container Registry (ACR). ACR is an Azure service that lets you install and operate Docker containers.

  1. Access the Azure Portal.
  2. To launch Azure Cloud Shell, click the terminal icon at the top.

Azure Cloud Shell is launched.Azure Cloud Shell is launched.

3. Make sure you choose the Bash shell from the list below.

Azure Cloud Shell BashAzure Cloud Shell Bash

4. Using the az group create command, build an Azure resource group to place an instance of ACR in.

> az group create –name <RGname> –location <Azure Region of choice>

Putting together a resource groupPutting together a resource group

5. Use the az acr create command to construct the ACR inside the resource group. The example below shows how to create an ACR with a Basic SKU with the admin-enabled option set to true. This is set to true since it enables resource management in the future.

> az acr create –resource-group <RGname> –name <ACRname> –sku Basic –admin-enabled true

Creating a Container Registry in AzureCreating a Container Registry in Azure

After you’ve finished, your resource group should now have an ACR instance running. Azure Docker hosting saves the day!

Locally connecting to the ACR instance

To complete the setup, you must now exit the Azure Cloud Shell and return to your native Windows machine.

  1. Launch PowerShell or a command prompt with administrator privileges on your local workstation. I’m going to use PowerShell.
  2. Using the Azure CLI, run az login and follow the on-screen steps to submit your credentials.
  3. You should see some JSON output identifying the user you just authenticated with after you’ve successfully authenticated.

Azure authenticationAzure authentication

4. Next, use the as acr login command in the Azure Cloud Shell to log in to the ACR instance you just built. I’m connecting to an ACR instance named nopacr1 in Azure resource group NOPRG, as seen below.

> az acr login –name <ACR-Name> –resource-group <RG Name>

Getting on ACRGetting on ACR

Docker Image Tag Updating

You may now push your local Docker image to your Azure Docker hosting or ACI ACR instance. However, you must first complete an ACR dependence. The name of the ACR instance must appear in the image name for any Docker images pushed to it.

  1. Using the command docker images, you may get the Docker image ID number or image name.

How to locate the ACR Docker imageHow to locate the ACR Docker image

2. Run the docker tag command to update the Docker image’s Docker image tag, as shown below. Use the ACR name of NOPACR1 and declare the tag as nopacr1.azurecr.io if you’re following the naming standard. Use the name dotnetsample for the picture itself.

> docker tag mcr.microsoft.com/dotnet/core/samples:aspnetapp <ACRName>.azurecr.io/<imagenameofchoice>

The Docker tag has been updated.The Docker tag has been updated.

3. Use the docker images command to double-check that the tag has been applied. The tag should now be changed, as you can see.

Docker tag verificationDocker tag verification

Uploading and verifying the Docker Image on the ACR Instance

  1. Now use the docker push command to upload the local image to the ACR instance using the dns name label where the ACR instance is located, as shown below.

> docker push <ACRName>.azurecr.io/<nameofimage>

ACR is receiving a Docker image.ACR is receiving a Docker image.

2.   Once uploaded, verify the push to the ACR instance went fine by using the Azure Portal by navigating to All Services —> Azure Container Registries and selecting the ACR instance you created earlier.

Using the Azure portal to inspect an ACR instanceUsing the Azure portal to inspect an ACR instance

3. Select Repositories from the Services part of the blade menu on the left. Your ACR instance should now be visible thanks to the Docker image that was recently deployed.

Examining the Docker repositoryExamining the Docker repository

4. Click on the picture to view a larger version as well as some further information.

Docker image inspectionDocker image inspection

The Azure Container Instance is being used (ACI)

You’ve now built an ACR instance, referenced a Docker container image with the ACR name, and pushed it to the ACR instance. Now you may launch the Docker image saved in your ACR instance using Azure Container Instance (ACI).

  1. Continuing from the previous step, choose Run instance by clicking the… next to latest. The Create Container Instance blade will appear.

Creating an instance of a containerCreating an instance of a container

2. Use the following information to fill up the boxes in the Create container instance box below:

  • Container Name — give this running container whatever name you choose.
  • Linux is the operating system. (The source container determines this.) This may be Windows if you’re using the same container in this project.)
  • Azure Subscription – your subscription to Azure
  • Any existing or new Azure Resource Group to which the container instance should be added.
  • depending on the resource group’s location

All other parameters may be left untouched for this Azure Docker instructional ASP.NET container. In a production environment, these values may need to be changed based on the container.

Creating an instance of a containerCreating an instance of a container

3. To construct the Container instance, press OK. 4. You should see a screen similar to the one below after the container instance has been launched.

Deploying a container instance successfullyDeploying a container instance successfully

5.   Once the deployment is finished, open the ACI in the portal by navigating to All Services —> Container Instances. Once here, browse to the Azure Container Instance (ACI) that just got created. You should see the instance shown below.

Examining the newly formed container instanceExamining the newly formed container instance

6.   Copy the IP address in the upper-right corner and paste it into a web browser. Your A sample ASP.NET web application should load from your Azure Container Instance (ACI) and display a web page as shown below.

ASP.NET Core website exampleASP.NET Core website example

When you’re through utilizing this container, use the az container delete command to get rid of it.

Conclusion

This Azure Docker lesson should have provided you with a basic grasp of ACI and how Docker images are stored in Azure.

The “azure container instances vs docker” is a tutorial that explains the differences between an Azure Container Instance and Docker.

Related Tags

  • azure container app tutorial
  • azure container instances
  • azure aci vs vm
  • azure container registry tutorial
  • deploy docker container to azure

Table of Content