Deploy .NET applications to Arm Virtual Machines and Container Registry in Microsoft Azure
Introduction
Motivation
Creating the Virtual Machine
Connecting to the Virtual Machine
Installing application dependencies and running the application
Create a Dockerfile using Visual Studio Code
Building a Docker image
Azure Container Registry
Pushing the local image to Azure Container Registry
Next Steps
Deploy .NET applications to Arm Virtual Machines and Container Registry in Microsoft Azure
Objective
In this step, you will install the following tools in the virtual machine:
- .NET 7 SDK – to build and run the application
- git – to clone application sources
Next, you will use git to clone application sources and finally, you will build and launch the application.
Dependencies
To install .NET SDK:
- In the terminal of the virtual machine type:
wget https://dot.net/v1/dotnet-install.sh
This will download the installation script.
- Make the script executable:
chmod +x dotnet-install.sh
- Run the script (it will install .NET SDK 7 under the folder .dotnet):
./dotnet-install.sh --channel 7.0
- Add the .dotnet folder to the PATH by typing:
export PATH="/home/arm/.dotnet/:$PATH"
- To check that the installation was successful, type:
dotnet --list-sdsk
To install git, use the terminal of the virtual machine and type:
sudo apt-get install -y git-all
Wait for the installation to be completed. It will take a while.
Clone and run the application
You will now clone the application by typing:
git clone https://github.com/dawidborycki/People.WebApp.git
The application sources will be cloned to the People.WebApp folder. Change the working directory to:
cd People.WebApp/
Then, run the application so that it will listen for requests on port 8080:
dotnet run --urls "http://0.0.0.0:8080"
After completing this step, you will see the following output:
Figure 14. Cloning and running the application
The application is ready and listening for the requests on port 8080. However, the network traffic is blocked on all ports except 22. You will need to configure the Network Security Group to enable the traffic.
Configure Network Security Group
To allow traffic on port 8080 for the Virtual Machine vm-arm64, proceed as follows:
- In the search box of the Azure Portal, type vm-arm64 and select this resource
- In the vm-arm64 screen, click the Networking tab on the left (it’s under Settings). You will see the following screen:
Figure 15. Networking tab of the virtual machine
In the Networking tab of the Virtual Machine, click the Add inbound port rule button (it’s on the right). This will open a new popup window Add inbound security rule:
Figure 16. Adding inbound port rule
Ensure the rule is configured as follows:
- Source: Any
- Source port ranges: *****
- Destination: Any
- Service: Custom
- Destination port ranges: 8080
- Protocol: Any
- Action: Allow
- Priority: 310
- Name: AllowAnyCustom8080Inbound
Then, click Add and wait for the security rule to be applied.
Once this is done, open your web browser and type the public IP address of your VM followed by 8080 port: 52.149.156.228:8080. You’ll see that the application is up and running:
Figure 17. An application deployed to Azure virtual machine
Summary
This part of the tutorial has shown you how to create an arm64-powered Virtual Machine in Microsoft Azure, how to connect to that VM using SSH, and how to install the tools required to build and run the .NET web application. Finally, you have learned how to configure a network security group to enable inbound traffic on port 8080.