How to troubleshoot container startup failure

Ho Fook Eng 0 Reputation points
2023-03-23T18:35:08.59+00:00

Can't find what else is wrong. Please help. I am using vanilla nodeJS for learning purposes. Not exploring frameworks at current state.

Directory :

User's image

Test.js contains the server codes:

enter image description here

Default docker output:

enter image description here

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,666 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Ho Fook Eng 0 Reputation points
    2023-03-23T18:47:34.2066667+00:00

    Have to serve 404 html file.


  2. Ayomide Oluwaga 961 Reputation points
    2023-03-23T19:30:48.35+00:00

    Container startup failures can be caused by a variety of issues. Here are some steps you can take to troubleshoot the issue:

    1. Check the container logs: The first step in troubleshooting container startup failures is to check the container logs. Azure provides a built-in log streaming feature that allows you to view the logs in real-time. You can also view the logs using the Azure portal, Azure CLI, or other third-party tools. Look for any error messages or stack traces that might indicate the cause of the failure.
    2. Check the container image: Make sure that the container image is properly configured and contains all the necessary dependencies. If you're using a custom image, ensure that it was built correctly and that all the required packages are installed. If you're using a pre-built image, ensure that it is the correct version and that it hasn't been corrupted.
    3. Check the container configuration: Ensure that the container configuration is correct, including the command that starts the Node.js application. Make sure that the command is correct and that it includes the correct path to the application.
    4. Check the container environment variables: Ensure that any environment variables required by the Node.js application are properly set. You can set environment variables in the Dockerfile, the Azure portal, or using the Azure CLI.
    5. Check the Azure deployment configuration: Ensure that the Azure deployment configuration is correct. Make sure that the container image and tag are correct, and that any required ports are properly configured.
    6. Check the Azure resource limits: Ensure that the resource limits for the Azure resource hosting the container are sufficient. If the Node.js application requires a lot of memory or CPU, you may need to increase the resource limits.
    7. Try running the container locally: If possible, try running the container locally using Docker or another container platform. This can help you isolate the issue and identify any configuration problems.
    8. Consult the Node.js documentation: Finally, consult the Node.js documentation to ensure that your application is properly configured and that you're following best practices. The Node.js community is active and helpful, so don't hesitate to ask for help if you're stuck.

    I hope these tips help you troubleshoot your container startup failure. Good luck!

    0 comments No comments

  3. ajkuma 25,781 Reputation points Microsoft Employee
    2023-03-24T07:08:39.6066667+00:00

    @Ho Fook Eng ,

    Just to clarify, what is the exact error message you receive when you navigate to your site?
    What deployment method are you leveraging? (Zip package, Git Repo, FTPs, VS, etc)
    Do the WebApp work fine locally?

    Based on my understand of your scenario, your Linux WebApp on App Service is failing on load on start-up.

    Node.js apps must be deployed with all the required NPM dependencies. The App Service deployment engine automatically runs ``` npm install –production` `` for you when you deploy a Git repository, or a Zip package with build automation enabled.

     

    Starting from Node 14 LTS, the container doesn't automatically start your app with PM2.

    To start your app with PM2, set the startup command to 
    pm2 start <.js-file-or-PM2-file> --no-daemon

    Ensure to use the --no-daemon argument because PM2 needs to run in the foreground for the container to work properly.

     

    Please check this doc for more info: customize-build-automation

    Configure a Node.js app for Azure App Service

    In the left navigation, click on Diagnose and solve problems – Checkout the tile for “Diagnostic Tools” > “Availability and Performance” & "Best Practices" and review to fetch additional information to isolate further.

     

    -- You may enable logs from Azure Portal (App Service logs blade) to fetch more pointers on the error. You may enable these logs– Application logging, Web Server logging, Detailed Error Messages

     --Kindly checkout the process here - >>Enable diagnostics logging for apps in Azure App Service

    Just to highlight, in order for Kudu to detect a Node.js app, you need a package.json file and an app.js/index.js in the root of your folder. It's also recommended to correctly set the start script in the package.json file https://docs.npmjs.com/misc/scripts#default-values 

    If the deployment steps run correctly, however, the app fails to start due to a missing npm package, note that only "dependencies" are installed, "devDependencies" are not installed by default.

     

    The default web.config file can be viewed at this URL https://github.com/projectkudu/kudu/wiki/Using-a-custom-web.config-for-Node-apps 

    Additionally, when deploying a Node app via git, Kudu automatically generates a web.config file which sets up everything for iisnode. If you wish to use  a custom web.config, you can start with what would normally be generated. 

    Kindly let us know how it goes, I'll follow-up with you further.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.