AG5 Deploying+compute+workloads+by+using+images+and+containers Ed2
AG5 Deploying+compute+workloads+by+using+images+and+containers Ed2
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
Instances.
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.
2. In the search box, enter the text Resource Group, and then select Enter.
ii. In the Resource group text box, enter the value ContainerCompute.(or any value
iii. In the Region drop-down list, select the (US) East US location.
[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.
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.
i. A dialog box prompts you to create a new storage account to begin using the shell.
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
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
az –version
[email protected] 7
3. Enter the following command, and then select Enter to create a new virtual machine with
[email protected] 8
Note: Replace the values of reaource group, Name, Username and password according to
Note 2: Wait for the VM creation process to complete. After the process completes, the command
4. Enter the following command, and then select Enter to list all the IP addresses associated
5. Enter the following command, and then select Enter to filter the output to only return the
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
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
10. The SSH tool will then ask you for a password. Enter “your password”, and then select
11. After connecting to the VM by using SSH, enter the following command, and then select
uname -a
exit
[email protected] 11
4 CREATE A DOCKER CONTAINER IMAGE AND DEPLOY IT TO
AZURE CONTAINER REGISTRY
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
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
[email protected] 13
6. Enter the following command, and then select Enter to create a new file in the
touch Dockerfile
7. Enter the following command, and then select Enter to open the embedded graphical editor
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:
if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
System.Console.WriteLine("Current IP Addresses:");
[email protected] 15
// Get host entry for current hostname
System.Console.WriteLine($"\t{address}");
else
[email protected] 16
11. Save the Program.cs file by using the menu in the graphical editor or the Ctrl+S keyboard
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
[email protected] 18
15. Copy and paste the following code into the Dockerfile file:
WORKDIR /app
COPY . ./
[email protected] 19
16. Save the Dockerfile file by using the menu in the graphical editor or by using the Ctrl+S
keyboard shortcut.
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
ii. Leave the Subscription text box set to its default value.
iii. In the Resource group drop-down list, select the existing ContainerCompute
option.
[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
2. At the Cloud Shell command prompt in the portal, enter the following command, and then
az acr list
[email protected] 22
3. Enter the following command, and then select Enter:
[email protected] 23
echo $acrName
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:
[email protected] 24
4. Close the Cloud Shell pane in the portal.
2. From the Resource groups blade, find and then select the ContainerCompute resource
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.
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
2. From the Resource groups blade, find and then select the ContainerCompute resource
3. From the ContainerCompute blade, select the container registry that you created earlier
in this lab.
5. From the Update container registry blade, perform the following actions:
[email protected] 28
6. Close the blade.
Repositories link.
[email protected] 29
3. From the Repository blade, select the ellipsis menu associated with the latest tag entry.
5. From the Create container instance blade, perform the following actions:
iv. Leave the Subscription text box set to its default value.
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.
4. Find the tabs from the Create Container Instances blade, such as Basics, Networking,
and Advanced.
vi. In the Registry drop-down list, select the Azure Container Registry resource that
[email protected] 32
viii. In the Image tag drop-down list, select latest.
7. Select Create to create the container instance by using your specified configuration.
2. From the Resource groups blade, find and then select the ContainerCompute resource
3. From the ContainerCompute blade, select the manualcompute container instance that
[email protected] 33
4. From the Container Instance blade, find the Settings section, and then select the
Containers link.
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,
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
[email protected] 35
6 SUMMARY
This completes step by step guide covering:
Create a VM by using the Azure Command-Line Interface (CLI).
Instances.