0% found this document useful (0 votes)
39 views

AG5 Deploying+compute+workloads+by+using+images+and+containers Ed2

This document provides steps to create a VM and deploy a container image to Azure services. It describes creating a VM using the Azure CLI, building a .NET application into a Docker container image and deploying it to Azure Container Registry, and automatically deploying the container image from the registry to Azure Container Instances.

Uploaded by

saphana9800
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

AG5 Deploying+compute+workloads+by+using+images+and+containers Ed2

This document provides steps to create a VM and deploy a container image to Azure services. It describes creating a VM using the Azure CLI, building a .NET application into a Docker container image and deploying it to Azure Container Registry, and automatically deploying the container image from the registry to Azure Container Instances.

Uploaded by

saphana9800
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Deploying compute workloads by using

images and containers


[Edition 02]

[Last Update 201011]

Atul Kumar
Oracle ACE & Cloud Expert

[email protected] 1
Contents
1 Introduction .................................................................................................................................................. 3
1.1 Lab Scenario .......................................................................................................................................................... 3
2 Documentation Links .................................................................................................................................. 4
3 Create a VM by using the Azure CLI ......................................................................................................... 5
3.1 Create a resource group ..................................................................................................................................... 5
3.2 Create VM using Azure Cloud Shell.................................................................................................................. 6
4 Create a Docker container image and deploy it to Azure Container Registry.......................... 12
4.1 Create and test a .NET application .................................................................................................................12
4.2 Create a Container Registry resource...........................................................................................................20
4.3 Open Azure Cloud Shell and store Container Registry metadata .........................................................22
4.4 Deploy a Docker container image to Container Registry ........................................................................24
4.5 Validate your container image in Container Registry..............................................................................25
5 Deploy an Azure container instance .................................................................................................... 28
5.1 Enable the admin user in Container Registry.............................................................................................28
5.2 Automatically deploy a container image to an Azure container instance ..........................................29
5.3 Manually deploy a container image to Container Instances ..................................................................32
5.4 Validate that the container instance ran successfully .............................................................................33
6 Summary ..................................................................................................................................................... 36

[email protected] 2
1 INTRODUCTION

This activity guide cover steps to

 Create a VM by using the Azure Command-Line Interface (CLI).

 Deploy a Docker container image to Azure Container Registry.

 Deploy a container from a container image in Container Registry by using Container

Instances.

1.1 Lab Scenario


You're tasked with evaluating multiple compute services in Microsoft Azure and determining which

service can help you automatically create VMs and install custom software on those machines. As

a proof of concept, you have decided to try creating VMs from built-in images and container

images so that you can compare the two solutions. To keep your proof of concept simple, you'll

create a special “IP check” application written in .NET that you'll automatically deploy to your

machines. Your proof of concept will evaluate the Azure Container Instances and Azure Virtual

Machines services.

[email protected] 3
2 DOCUMENTATION LINKS
1. Running Debian virtual machines in Azure: https://azure.microsoft.com/en-
in/blog/running-debian-in-azure/
2. What is a Container? : https://www.docker.com/resources/what-container
3. Azure Container Registry: https://docs.microsoft.com/en-in/azure/container-registry/

[email protected] 4
3 CREATE A VM BY USING THE AZURE CLI
In this section, we will create a Resource Group and a Debian Virtual Machine.

3.1 Create a resource group


1. In the Azure portal's navigation pane, select the Create a resource link.

2. In the search box, enter the text Resource Group, and then select Enter.

3. From the Resource group blade, select Create.

4. From the Basics tab, perform the following actions:

i. Leave the Subscription text box set to its default value.

ii. In the Resource group text box, enter the value ContainerCompute.(or any value

according to your choice)

iii. In the Region drop-down list, select the (US) East US location.

iv. Select Review + Create.

[email protected] 5
5. From the Review + Create tab, review the options that you selected during the previous

steps.

6. Select Create to create the resource group by using your specified configuration.

3.2 Create VM using Azure Cloud


Shell
1. In the portal, select the Cloud Shell icon to open a new shell instance.

Note: The Cloud Shell icon is represented by a greater than sign () and underscore

character (_).

[email protected] 6
2. If this is your first time opening Cloud Shell using your subscription, you can use the

Welcome to Azure Cloud Shell Wizard to configure Cloud Shell for first-time usage.

Perform the following actions in the wizard:

i. A dialog box prompts you to create a new storage account to begin using the shell.

Accept the default settings, and then select Create storage.

Note: Wait for Cloud Shell to finish its initial setup procedures before moving forward with

the lab. If you don't notice the Cloud Shell configuration options, this is most likely

because you're using an existing subscription with this course's labs. The labs are written

with the presumption that you're using a new subscription.

ii. At the Cloud Shell command prompt in the portal and Select Bash from the Top

Left drop-down list , enter the following command, and then select Enter to get the

version of the Azure CLI tool:

az –version

[email protected] 7
3. Enter the following command, and then select Enter to create a new virtual machine with

the following settings:

i. Resource group: ContainerCompute (one which you created before)

ii. Name: quickvm (according to your choice)

iii. Image: Debian

iv. Username: Student (according to your choice)

v. Password: (according to your choice)

az vm create --resource-group ContainerCompute --name quickvm --image Debian --admin-

username student --admin-password ######

[email protected] 8
Note: Replace the values of reaource group, Name, Username and password according to

the one which you want to select.

Note 2: Wait for the VM creation process to complete. After the process completes, the command

will return a JSON file containing details about the machine.

4. Enter the following command, and then select Enter to list all the IP addresses associated

with the VM:

az vm list-ip-addresses --resource-group ContainerCompute --name quickvm

5. Enter the following command, and then select Enter to filter the output to only return the

first IP address value:

az vm list-ip-addresses --resource-group ContainerCompute --name quickvm --query

'[].{ip:virtualMachine.network.publicIpAddresses[0].ipAddress}' --output tsv


[email protected] 9
6. Enter the following command, and then select Enter to store the results of the previous

command in a new Bash shell variable named ipAddress:

ipAddress=$(az vm list-ip-addresses --resource-group ContainerCompute --name

quickvm --query '[].{ip:virtualMachine.network.publicIpAddresses[0].ipAddress}' --

output tsv)

7. Enter the following command, and then select Enter to render the value of the Bash shell

variable ipAddress:

echo $ipAddress

8. Enter the following command, and then select Enter to connect to the VM that you created

earlier in this lab by using the Secure Shell (SSH) tool and the IP address stored in the

Bash shell variable ipAddress:

ssh student@$ipAddress

[email protected] 10
9. The SSH tool will first inform you that the authenticity of the host can’t be established and

then ask if you want to continue connecting. Enter yes, and then select Enter to continue

connecting to the VM.

10. The SSH tool will then ask you for a password. Enter “your password”, and then select

Enter to authenticate with the VM.

11. After connecting to the VM by using SSH, enter the following command, and then select

Enter to get metadata describing the Linux VM:

uname -a

12. Use the exit command to end your SSH session:

exit

[email protected] 11
4 CREATE A DOCKER CONTAINER IMAGE AND DEPLOY IT TO
AZURE CONTAINER REGISTRY

4.1 Create and test a .NET


application
1. In the Azure portal's navigation pane, select the Cloud Shell icon to open a new shell

instance.

2. At the Cloud Shell command prompt in the portal, enter the following command, and then

select Enter to move from the root directory to the ~/clouddrive directory:

cd ~/clouddrive

3. Enter the following command, and then select Enter to create a new directory named

ipcheck in the ~/clouddrive directory:

mkdir ipcheck

[email protected] 12
4. Enter the following command, and then select Enter to change the active directory from

~/clouddrive to ~/clouddrive/ipcheck:

cd ~/clouddrive/ipcheck

5. Enter the following command, and then select Enter to create a new .NET console

application in the current directory:

dotnet new console --output . --name ipcheck

[email protected] 13
6. Enter the following command, and then select Enter to create a new file in the

~/clouddrive/ipcheck directory named Dockerfile:

touch Dockerfile

7. Enter the following command, and then select Enter to open the embedded graphical editor

in the context of the current directory:

code .

8. In the graphical editor, find the FILES pane, and then open the Program.cs file to open it in
the editor.

[email protected] 14
9. Delete the entire contents of the Program.cs file.

10. Copy and paste the following code into the Program.cs file:

public class Program

public static void Main(string[] args)

// Check if network is available

if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())

System.Console.WriteLine("Current IP Addresses:");

[email protected] 15
// Get host entry for current hostname

string hostname = System.Net.Dns.GetHostName();

System.Net.IPHostEntry host = System.Net.Dns.GetHostEntry(hostname);

// Iterate over each IP address and render their values

foreach(System.Net.IPAddress address in host.AddressList)

System.Console.WriteLine($"\t{address}");

else

System.Console.WriteLine("No Network Connection");

[email protected] 16
11. Save the Program.cs file by using the menu in the graphical editor or the Ctrl+S keyboard

shortcut. Don't close the graphical editor.

12. Back at the command prompt, enter the following command, and then select Enter to run

the application:

dotnet run

[email protected] 17
13. Find the results of the run. At least one IP address should be listed for the Cloud Shell

instance.

14. In the graphical editor, find the FILES pane of the editor, and then open the Dockerfile file

to open it in the editor.

[email protected] 18
15. Copy and paste the following code into the Dockerfile file:

# Start using the .NET Core 3.1 SDK container image

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build

# Change current working directory

WORKDIR /app

# Copy existing files from host machine

COPY . ./

# Publish application to the "out" folder

RUN dotnet publish --configuration Release --output out

# Start container by running application DLL

ENTRYPOINT ["dotnet", "out/ipcheck.dll"]

[email protected] 19
16. Save the Dockerfile file by using the menu in the graphical editor or by using the Ctrl+S

keyboard shortcut.

17. Close the Cloud Shell pane in the portal.

4.2 Create a Container Registry


resource
1. In the Azure portal's navigation pane, select the Create a resource link.

2. In the search box, enter Container Registry, and then select Enter.

[email protected] 20
3. From the Create container registry blade, perform the following actions:

i. In the Registry name text box, give your registry a globally unique name.

Note: The blade will automatically check the name for uniqueness and inform

you if you're required to choose a different name.

ii. Leave the Subscription text box set to its default value.

iii. In the Resource group drop-down list, select the existing ContainerCompute

option.

iv. In the Location text box, select East US.

v. In the SKU drop-down list, select Basic.

vi. Select Create.

[email protected] 21
4.3 Open Azure Cloud Shell and
store Container Registry
metadata
1. In the portal, select the Cloud Shell icon to open a new shell instance.

Note: Wait for Cloud Shell to finish connecting to an instance before moving forward

with the lab.

2. At the Cloud Shell command prompt in the portal, enter the following command, and then

select Enter to get a list of all container registries in your subscription:

az acr list

[email protected] 22
3. Enter the following command, and then select Enter:

az acr list --query "max_by([], &creationDate).name" --output tsv

4. Enter the following command, and then select Enter:

acrName=$(az acr list --query "max_by([], &creationDate).name" --output tsv)

5. Enter the following command, and then select Enter:

[email protected] 23
echo $acrName

4.4 Deploy a Docker container


image to Container Registry
1. Enter the following command, and then select Enter to change the active directory from ~/

to ~/clouddrive/ipcheck:

cd ~/clouddrive/ipcheck

2. Enter the following command, and then select Enter to get the contents of the current

directory:

dir

3. Enter the following command, and then select Enter to upload the source code to your

container registry and build the container image as a Container Registry task:

az acr build --registry $acrName --image ipcheck:latest .

[email protected] 24
4. Close the Cloud Shell pane in the portal.

4.5 Validate your container


image in Container Registry
1. In the Azure portal's navigation pane, select the Resource groups link.

2. From the Resource groups blade, find and then select the ContainerCompute resource

group that you created earlier in this lab.

3. From the ContainerCompute blade, select the container registry that you created earlier in

this lab.

4. From the Container Registry blade, find the Services section, and then select the

Repositories link.

[email protected] 25
5. In the Repositories section, select the ipcheck container image repository.

6. From the Repository blade, select the latest tag.

7. Find the metadata for the version of your container image with the latest tag.

Note: You can also select the Run ID link to find metadata about the build task.

[email protected] 26
Summary: In this Section, you created a .NET console application to display a machine’s current

IP address. You then added the Dockerfile file to the application so that it could be converted into

a Docker container image. Finally, you deployed the container image to Container Registry.

[email protected] 27
5 DEPLOY AN AZURE CONTAINER INSTANCE

5.1 Enable the admin user in


Container Registry
1. In the Azure portal's navigation pane, select the Resource groups link.

2. From the Resource groups blade, find and then select the ContainerCompute resource

group that you created earlier in this lab.

3. From the ContainerCompute blade, select the container registry that you created earlier

in this lab.

4. From the Container Registry blade, select Update.

5. From the Update container registry blade, perform the following actions:

i. In the Admin user section, select Enable.

ii. Select Save.

[email protected] 28
6. Close the blade.

7. Close the Update container registry blade.

5.2 Automatically deploy a


container image to an Azure
container instance
1. From the Container Registry blade, find the Services section, and then select the

Repositories link.

2. In the Repositories section, select the ipcheck container image repository.

[email protected] 29
3. From the Repository blade, select the ellipsis menu associated with the latest tag entry.

4. In the pop-up menu, select the Run instance link.

5. From the Create container instance blade, perform the following actions:

i. In the Container name text box, enter managedcompute.


[email protected] 30
ii. Leave the Container image text box set to its default value.

iii. In the OS type section, select Linux.

iv. Leave the Subscription text box set to its default value.

v. In the Resource group drop-down list, select ContainerCompute.

vi. In the Location drop-down list, select East US.

vii. In the Number of cores drop-down list, select 2.

viii. In the Memory (GB) text box, enter 4.

ix. In the Public IP address section, select No.

x. Select OK.

[email protected] 31
5.3 Manually deploy a container
image to Container Instances
1. In the Azure portal's navigation pane, select the Create a resource link.

2. In the search box, enter Container instance, and then select Enter.

3. From the Container Instances blade, select Create.

4. Find the tabs from the Create Container Instances blade, such as Basics, Networking,

and Advanced.

5. From the Basics tab, perform the following actions:

i. Leave the Subscription text box set to its default value.

ii. In the Resource group drop-down list, select ContainerCompute.

iii. In the Container name text box, enter manualcompute.

iv. In the Region drop-down list, select (US) East US.

v. In the Image source section, select Azure Container Registry.

vi. In the Registry drop-down list, select the Azure Container Registry resource that

you created earlier in this lab.

vii. In the Image drop-down list, select ipcheck.

[email protected] 32
viii. In the Image tag drop-down list, select latest.

ix. Select Review + Create.

6. From the Review + Create tab, review the selected options.

7. Select Create to create the container instance by using your specified configuration.

5.4 Validate that the container


instance ran successfully
1. In the Azure portal's navigation pane, select the Resource groups link.

2. From the Resource groups blade, find and then select the ContainerCompute resource

group that you created earlier in this lab.

3. From the ContainerCompute blade, select the manualcompute container instance that

you created earlier in this lab.

[email protected] 33
4. From the Container Instance blade, find the Settings section, and then select the

Containers link.

5. In the Containers section, find the list of Events.

6. Select the Logs tab, and then find the text logs from the container instance.

[email protected] 34
Note: After the application finishes running, the container terminates because it has

completed its work. For the manually created container instance, you indicated that a

successful exit was acceptable, so the container ran once. The automatically created

instance didn't offer this option, and it assumes the container should always be running,

so you'll notice repeated restarts of the container.

Summary: In this section, you used multiple methods to deploy a container image to an Azure

container instance. By using the manual method, you were also able to customize the deployment

further and to run task-based applications as part of a container run.

[email protected] 35
6 SUMMARY
This completes step by step guide covering:
 Create a VM by using the Azure Command-Line Interface (CLI).

 Deploy a Docker container image to Azure Container Registry.

 Deploy a container from a container image in Container Registry by using Container

Instances.

[email protected] 36

You might also like