Troubleshooting Application Error on Azure App Service
Case Study: Error on Image pull from Azure Container Registry to App Service
Running into application errors on your Azure App Service can be frustrating, but they are not uncommon. These errors can occur due to various factors, ranging from code issues to configuration problems or resource limitations.
As an Azure App Service user, you may have encountered application errors at some point, especially when they are preventing your application from functioning as expected. Fortunately, Azure App Service provides a range of troubleshooting tools that can help you identify and resolve these errors.
In this article, we will explore some effective troubleshooting steps to help you diagnose and resolve application errors on your Azure App Service and also a step-by-step guide to troubleshooting application errors on Azure App Service using an Image Pull Error from App Service Container
Introduction to Azure App Service and Application Errors
Azure App Service is a fully managed platform for building, deploying, and scaling web applications. It supports several programming languages, including .NET, Java, Node.js, PHP, and Python. With Azure App Service, you can focus on developing your application without worrying about the underlying infrastructure.
However, despite its many benefits, Azure App Service can also be prone to application errors. Application errors occur when your application fails to function as expected. These errors can be caused by a range of factors, including code issues, networking issues, and configuration issues. When you encounter an application error on Azure App Service, it is important to understand the type of error you are dealing with and its underlying cause.
Understanding Application Error Types
There are several types of application errors that you may encounter on Azure App Service. These include:
HTTP Errors
HTTP errors occur when a client sends a request to your web application, but the server is unable to process the request. HTTP errors are usually caused by issues with the client request, server configuration, or server capacity. Examples include 403 (Forbidden) , 500 (Internal Server Error)
Runtime Errors
Runtime errors occur when your application fails to execute properly at runtime. These errors can be caused by issues with your code or the environment in which your application is running.
Configuration Errors
Configuration errors occur when your application is not configured correctly. Issues with your application settings, database connections, or environment variables can cause these errors.
Network Errors
Network errors occur when there is a problem with the network connection between your application and the client. These errors can be caused by issues with the client network, server network, or network configuration.
Understanding the type of application error you are dealing with is the first step in troubleshooting the error.
Common Causes of Application Errors on Azure App Service
Now that you understand the different types of application errors, let's take a look at some of the common causes of application errors on Azure App Service.
Code Issues
Code issues are one of the most common causes of application errors on Azure App Service. These issues can include syntax errors, logic errors, or errors that occur due to changes in the codebase. To prevent code issues from causing application errors, it is important to follow best practices for coding and testing your application.
Configuration Issues
Configuration issues can also cause application errors on Azure App Service. Problems with your application settings, database connections, or environment variables can cause these issues. To prevent configuration issues from causing application errors, it is important to ensure that your application is configured correctly and that all dependencies are properly installed.
Sample Resource Connectivity issue - Image sourced from Google search
Azure App Service Troubleshooting Tools
Azure App Service provides a range of troubleshooting tools that can help you identify and resolve application errors. These tools include:
Application Insights
Application Insights is a monitoring and diagnostic tool that can help you identify and troubleshoot application errors on Azure App Service. It provides detailed insights into application performance, including metrics such as response time, availability, and user session data.
Log Stream
Log Stream is a real-time log viewer that can help you troubleshoot application errors on Azure App Service. It provides a live stream of log data, allowing you to quickly identify and diagnose issues with your application.
Diagnostics Logs
Diagnostics Logs is a feature that allows you to capture detailed diagnostic information about your application. This information can be used to troubleshoot issues with your application, including errors and performance issues.
Troubleshooting Application Error
Case Study -ERROR - Image pull failed: Verify docker image configuration and credentials unauthorized: authentication required
Case Study: Azure Pipeline Deployment From ACR to App Service
Case study Architecture - Using Azure Pipelines to Pull App Image from ACR to App Service.
In this case study, we examine a straightforward NodeJs App hosted on Azure Repo. With a Docker file set up to construct the NodeJS image, the pipeline effectively builds the image to ACR.
The goal is to then pull that same image from ACR for deployment on Azure App service. The release pipeline was completed successfully since the scope of this simulation didn't cover post-deployment testing.
Despite the deployment processes seemingly running smoothly, accessing the App Service URL results in an unwelcome "Application Error" message.
Understand the Error Message
When encountering an application error, the first step is to examine the error message or logs carefully. These messages often contain valuable information about the specific issue that caused the error. Understanding the error message will give you a starting point for troubleshooting.
The question will be where are the logs? App service provides a Source Management console (SCM) known as, KUDU. The Kudu portal is very useful for managing files, running console scripts for Linux environments, and also for troubleshooting.
Steps to Locate SCM portal
Log on to portal.azure.com
Open App Service and search for Advanced Tools
- This opens the SCM page known as Kudu, your kudu interface will look like this when you add /newui to the URL as seen https://<appservicename>.scm.azurewebsites.net/newui
- Navigate to File Manager and open LogsFiles. Here is the error on my app service web app. My application is trying to pull an image from my Azure Container Registry (ACR) to App Service
2023-07-15T02:10:35.228Z WARN - Image pull failed. Defaulting to local copy if present. 2023-07-15T02:10:35.283Z ERROR - Image pull failed: Verify docker image configuration and credentials (if using private repository) 2023-07-15T02:10:35.430Z INFO - Stopping site xxxx because it failed during startup. 2023-07-15T02:10:41.485Z INFO - Pulling image:
xxxxxx.azurecr.io/nodejsapp
2023-07-15T02:10:41.531Z ERROR - DockerApiException: Docker API responded with status code=InternalServerError, response={"message":"Get \"https://xxxx.[azurecr.io/v2/nodejsapp/manifests/latest\](http://azurecr.io/v2/nodejsapp/manifests/latest)": unauthorized: authentication required, visit
https://aka.ms/acr/authorization
for more information."}
From the logs, one can deduce that my App Service is unable to authenticate to pull from Azure Container Registry, hence the Image pull failed with an Unauthorised error
Resolution
Now that we understand the root cause it will be easy to research for a solution if you don't have answers on how to resolve this. In my case, the issue is clear and the resolution is to create an authorization for App Service to pull from Azure Container Registry and also add Authentication details to App Service.
Resolution Steps - Set Up Manage Identity
Setting up Manage Identity for App Service provides for App service to authenticate to another resource such as Azure Container Registry (ACR).
Step 1: Log on to App Service, find Identity, Enable system Assigned status, and Save
Step 2: Navigate to Azure container Registry >>Access Control (IAM), and assign ACRPul access to your App Service
Step 3: Select the web app as a member and click on Review +Assign
Next is to enable Authentication from the App service to ACR
Step 4: Open your Container Registry, navigate to Access Keys and Enable Admin User
Step 5: On App Service, navigate to configurations and Add the App Settings for Docker registry - DOCKER_REGISTRY_SERVER_USERNAME and DOCKER_REGISTRY_SERVER_PASSWORD enter value as seen in your container registry, save and restart App service.
Initiate a Pull again and monitor live logs. This time, you will see success in your logs, App service will be able to authenticate to ACR to pull your image.
In conclusion, troubleshooting application errors on Azure App Service can be a complex process. However, by understanding the different types of application errors, their common causes, and the troubleshooting tools available on Azure App Service, you can quickly identify and resolve these errors. By following best practices for preventing application errors, you can ensure that your application is always running smoothly on Azure App Service.
Do you find this article helpful, please like and drop your thoughts in the comment section.