How to configure custom environment variables to the docker containers running behind Azure App Service Web App

Chandra Pal, Madhab 0 Reputation points
2024-11-28T12:48:42.68+00:00

I am trying set some environment variables while running the docker container behind the Azure App Service. These are custom environment variables which will be picked up by Dynatrace oneagent component for RUM monitoring. I searched a lot but did not find any option to pass any custom environment variables other than the App Environment variables enabled for the Web App as explained here: https://learn.microsoft.com/en-us/azure/app-service/reference-app-settings?tabs=kudu%2Cdotnet#app-environment

Does anyone know any way to configure custom environment variable to the docker containers running behind the Azure Web App?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,000 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Shree Hima Bindu Maganti 1,065 Reputation points Microsoft Vendor
    2024-11-28T16:44:27.16+00:00

    Hi Chandra Pal, Madhab ,
    Welcome to the Microsoft Q&A Platform!
    To configure custom environment variables for Docker containers running behind Azure App Service,Since App Service doesn't allow direct modification of the container runtime environment outside the options provided by the App Settings interface.

    1. Navigate to your Azure App Service in the Azure Portal.
    2. Go to the Configuration section under Settings.
    3. Click on Application Settings.
    4. Add your custom environment variables by specifying their Key and Value. For example:
    5. Key: DT_CUSTOM_VARIABLE
    6. Value: some_value
    7. Save the changes. These variables will be injected into the environment of your container.
    8. Ensure that your Docker container is configured to read these environment variables.
    9. In your Dockerfile or application code, access the variables using the appropriate method .
    10. After saving the changes, restart your App Service to ensure the new environment variables are applied to the running container.
    11. you can verify that the variables have been set correctly by Using the Kudu console.
    12. Navigate to your Web App in the Azure Portal.
    13. Go to Development Tools > Advanced Tools (Kudu) > Go.
    14. Open the debug console and use commands like printenv or cat /proc/1/environ to inspect the container's environment variables.
    15. Pass Environment Variables Directly in Docker Compose (if applicable).If you are deploying using a custom Docker Compose file, include the environment variables in the environment.
    version: '3.8'
    services:
      app:
        image: your-image
        environment:
          - DT_CUSTOM_VARIABLE=some_value
    
    1. Ensure that your custom variables are aligned with Dynatrace's requirements.
      https://learn.microsoft.com/en-us/azure/app-service/reference-app-settings?tabs=kudu%2Cdotnet#app-environment
      https://docs.dynatrace.com/docs/manage/tags-and-metadata/setup/define-tags-based-on-environment-variables
      Let me know if you have any further assistances.
    0 comments No comments

  2. Chandra Pal, Madhab 0 Reputation points
    2024-11-29T08:04:15.05+00:00

    Hi Shree.

    I have already tried that way, I had configured the DT environment variables in the Setting of the We App's Environment Variables and I could also see the environment variables effective from the Kudu shell. But I don't see those DT environment variables are picked up by Dynatrace and that's because I suppose those are not configured in the environment before the Dynatrace OneAgent is invoked during container start.


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.